Page 1 of 1

Copying from Excel to Word

Posted: Wed Mar 11, 2020 7:56 am
by Natter
Hi,

There is a large Excel file. Based on this file, I need to make a report in Word format . I copy the Excel file into an array and create a Word document based on it.

itm:=oExc:Sheets(1):Range("A1:L10000"):Value

However, since the original Excel file contains specific characters (≥, м², etc. ), they are replaced with the "? " character when writing to Word. How can we solve this ? ( you can, of course, move fragments through the Clipboard, but it's very, very long)

Re: Copying from Excel to Word

Posted: Wed Mar 11, 2020 9:54 am
by nageswaragunupudi
original Excel file contains specific characters (degree, root, etc. ),
Do you mean characters like these?
Image

Re: Copying from Excel to Word

Posted: Wed Mar 11, 2020 11:15 am
by Natter
I mean these symbols - ≥, м², etc.

Re: Copying from Excel to Word

Posted: Wed Mar 11, 2020 3:12 pm
by nageswaragunupudi
Assume you are using Harbour.

Before opening Excel book, set codepage to UTF8

Code: Select all

   cp := HB_SETCODEPAGE( "UTF8" )
 
Now read from Excel and export to your Word document.
After finishing, you can restore your original codepage if you want to.

Code: Select all

 HB_SETCODEPAGE( cp )
 

Re: Copying from Excel to Word

Posted: Thu Mar 12, 2020 7:15 am
by Natter
I set HB_SETCODEPAGE ("UTF8") and read data from an Excel file. But Unicode characters could not be obtained. Solved the problem of copying text fragments with Unicode characters via Clipboard

Re: Copying from Excel to Word

Posted: Thu Mar 12, 2020 8:26 am
by nageswaragunupudi
If you are using Harbour, setting codepage to UTF8 works. I mentioned in my post that I assumed you are using Harbour. I posted my answer after testing and confirming at my end, as I always do.

If you are using xHarbour, it does not work, because xHarbour's OLE functions do not support UTF8.

Copying and pasting works in both Harbour and xHarbour.