Dear All,
I'm using Lazarus 1.6 , and try to do the same what i did in Delphi several years before at last:
Fill some cells by OLE office automation.
When i hardcoding the text to the program, it's export very well to Excel, but
if i want to send a variable to excel (for ex: edit1.text) just appear Chinese text, but nothing else...
Here is some code:
procedure TForm1.Button2Click(Sender: TObject);
begin
XLApp := CreateOleObject('Excel.Application');
try
XLApp.Visible := True;
XLApp.DisplayAlerts := True;
XLApp.Workbooks.Add; // Open the Workbook
XLApp.Cells[1,1].Value :='This is a Hardcoded text in program';
XLApp.Cells[2,1].Value :=edit2.text ;
end;
end;
finally
XLApp.ActiveWorkBook.SaveAs(edit1.text, 51); //here also save excel whith name full chinese chars...
end;
I took screenshot about the results....
I think there is must be a string conversation issue, but a couldn't figure it out what may wrong... Could you help in this , please?
---UPDATE---!
Very interesting! if i type:
XLApp.Cells[2,1].Value :=utf8Decode(edit2.text) ;
Stops with SIGSEGV error, but this is the conversion, what i was looking for...
But if i put in function
Function StrToWidestr(aString: String): WideString;
begin
Result:= UTF8Decode(aString);
end;
with
XLApp.Cells[2,1].Value :=StrToWidestr(edit2.text) ;
Its works! How this can be?
Another question:
Can you help me to find the command to change printer?
Xlapp.Application.ActivePrinter:='Xerox Phaser 3117' doesnt work... or how can i make sure the name of the printer exactly in the system?