Unicode Read from and write to excel

Unicode Read from and write to excel

Postby MarcoBoschi » Fri Nov 27, 2015 6:03 am

Now I am able to read and write from and to cells of Excel unicode characters

In this way
This a little program that read from the first record of a dbf table that contains in one field some chinese characters
and create a excel sheet write into cells
Then read from these cells and append a record into dbf table and populate the fields with the values of the cells


Many thanks to Mr Rao and Fwh support!



#include "fivewin.ch"

FUNCTION Main()

local oExcel, oBook, oSheet, oWnd, oClp
local nRow, nCol, nCols, uVal, uVal2

FW_SetUnicode( .t. )

DEFINE WINDOW oWnd
oClp := TClipboard():New()

USE "AA_CHN"
GO TOP
nCols := FCount()

oExcel := ExcelObj()
oBook := oExcel:WorkBooks:Add()
oSheet := oBook:ActiveSheet

uVal := FieldGet( 1 )
scrivicella( "A1" , uVal , oSheet , oClp )

uVal := FieldGet( 2 )
scrivicella( "B1" , uVal , oSheet , oClp )

uVal := FieldGet( 3 )
scrivicella( "C1" , uVal , oSheet , oClp )

oExcel:Visible := .T.
APPEND BLANK
fieldput( 1 , leggicella( "A1" , oSheet , oClp , oExcel ) )
fieldput( 2 , leggicella( "B1" , oSheet , oClp , oExcel ) )
fieldput( 3 , leggicella( "C1" , oSheet , oClp , oExcel ) )

oClp:End()
oWnd:End()

return nil

FUNCTION LEGGICELLA( cRange , oAs, oClp ,oExcel )
LOCAL cRitorna

oAs:Range( cRange ):Select()
oExcel:Selection:Copy()
cRitorna := oClp:GetUnicodeText()

RETURN cRitorna

FUNCTION SCRIVICELLA( cRange , uVal , oAs, oClp )
LOCAL uVal2 := TRIM( uVal )

IF ValType( uVal ) == 'C' .AND. IsUtf8( uVal2 )
oClp:SetText( uVal2 )
oAs:Range( cRange ):Select()
oAs:Paste()
oClp:Clear()
ELSE
oAs:Range( cRange ):Value := uVal2
ENDIF

RETURN NIL
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 66 guests