FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Create Excel from Fwh with Unicode characters
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Create Excel from Fwh with Unicode characters
Posted: Thu Nov 19, 2015 02:00 PM

Hi,
aa_chn.dbf is a dbf table that contains in des_chn field some chinese characters
If a create an excel worksheet and write into cell the "des_chn" field content they does not appear
as in the dbf field

#include "fivewin.ch"

ANNOUNCE RDDSYS

FUNCTION CRE_XLS()
LOCAL oExcel
LOCAL oAs
LOCAL nRow
FW_SetUnicode( .t. )

oExcel := CreateObject( "Excel.Application" )
oExcel:WorkBooks:Add()

oAs := oExcel:Activesheet()

SELECT 0
USE aa_chn
SET INDEX TO aa_chn
GO TOP
oAs:Range( "A1" ):Value := "English Description"
oAs:Range( "B1" ):Value := "Chinese Description"

nRow := 2
DO WHILE !EOF()
   IF !EMPTY( aa_chn->des_chn )
       MsgInfo( aa_chn->des_chn , aa_chn->descrizi )

       oAs:Range( "A" + cRow(nRow) ):Value := "'" + ALLTRIM( aa_chn->descrizi )
       oAs:Range( "B" + cRow(nRow) ):Value := "'" + ALLTRIM( aa_chn->des_chn )
       nRow ++
   ENDIF
   SKIP
ENDDO
oExcel:visible := .T.
USE
RETURN NIL


FUNCTION CROW( nRow )
LOCAL cRow := ALLTRIM( STR( nRow ) )
RETURN cRow


INIT PROCEDURE RddInit
REQUEST DBFFPT
REQUEST DBFCDX
rddSetDefault( "DBFCDX" )

RETURN
Marco Boschi
info@marcoboschi.it
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Create Excel from Fwh with Unicode characters
Posted: Thu Nov 19, 2015 10:54 PM

The bottleneck is the OleAuto implementations of (x)Harbour.

We are working on OLE alternative with Unicode support independent of (x)Harbour.

For now the solution is copy the utf8 text into clipboard and paste into Excel sheet using FWH 15.09. (In this version TClipBoard class supports Unicode). This is how XBrowse to Excel works with Unicode data.

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Create Excel from Fwh with Unicode characters
Posted: Fri Nov 20, 2015 04:26 AM

Here is a small example.
I have a dbf UTF8_01.DBF with Unicode contents for testing.

   
   DEFINE WINDOW oWnd
   USE UTF8_01
   aData    := FW_DbfToArray()
   AEval( aData, { |a,i| aData[ i ] := FW_ArrayAsList( a, Chr(9) ) } )
   aData    := FW_ArrayAsList( aData, CRLF )
   oClp     := TClipBoard():New()
   oClp:SetText( aData )
   oExcel   := ExcelObj()
   oBook    := oExcel:WorkBooks:Add()
   oSheet   := oBook:ActiveSheet
   oSheet:Cells( 1, 1 ):Select()
   oSheet:Paste()
   for n := 1 to 3
      oSheet:Columns( n ):AutoFit()
   next
   oClp:Clear()
   oExcel:Visible := .t.
   oWnd:End()

Regards



G. N. Rao.

Hyderabad, India
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Create Excel from Fwh with Unicode characters
Posted: Sat Nov 21, 2015 08:06 AM

Rao,
maybe the problem is my table but with fivedbu see the exact characters.
In Excel I do not see exact characters.
I use the latest version
Do you want to see my dbf table?
Marco

Marco Boschi
info@marcoboschi.it
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Create Excel from Fwh with Unicode characters
Posted: Sat Nov 21, 2015 09:02 AM

If you are using the latest version, you should be able to see the characters in xbrowse and oBrw:ToExcel() should also export correctly.
I am expecting that you are using utf-8 encoding. Prior to general acceptance and adoption of utf-8 for all languages, there was lot of work done and various encodings were developed for Chinese chars. Our library works only with general utf-8 encoding and this works for universal languages.
You may please send your dbf to my email and let me check too.

Regards



G. N. Rao.

Hyderabad, India
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Create Excel from Fwh with Unicode characters
Posted: Sat Nov 21, 2015 10:30 AM

Rao,
info@marcoboschi.it is my email
Thank you very much
Marco

Marco Boschi
info@marcoboschi.it

Continue the discussion