Special characters in excel spreadsheet generated in Delphi

Asked

Viewed 599 times

3

I found on the internet many codes related to generating EXCEL spreadsheets in DELPHI. Follow the code I am using:

objExcel := CreateOleObject('Excel.Application');
objExcel.Visible := True;

objExcel.Workbooks.Add;
objExcel.Workbooks[1].Sheets.Add;
objExcel.Workbooks[1].WorkSheets[1].Name := 'Orçamento';
Sheet := objExcel.Workbooks[1].WorkSheets[1];   

That part works, but when I add some information, like:

Sheet.Range['B4'] := 'M A T É R I A S   -   P R I M A S';  

In EXCEL changes the special characters, for example, to:

M A T Ã R I A S   -   P R I M A S   

Outside the fields lookup, as:

Sheet.Cells[l,2]:=dmOrcamentos.ztBaseOrcamento.FieldByName('MP_DESC').Text;

that the data stays like this:

䡃㠠〬‰䅓⁅〱㠰

How can I format the characters to look like they should?

  • Checked if the contents of dmOrcamentos.ztBaseOrcamento.Fieldbyname('MP_DESC'). Text is correct ?

2 answers

0

Try the following
Sheet.Range['B4'] := WideString('M A T É R I A S - P R I M A S');

  • Unfortunately it didn’t work @wesleyluan

  • @Will You should be doing Sheet.Range['B4']. Value = Widestring('xxxx'), by the way, what version of your Delphi? And what version of Excel are you interacting with?

  • @Eprogrammernotfound I ended up solving my problem using Fpspreadsheet for Lazarus. Still thanks for the friendly contact. I was using the 2010 version of Excel and Lazarus 1.4.0

0


I used Lazarus Fpspreadsheet to solve the problem. With the function:

MyWorksheet.WriteUTF8Text(linha, coluna, 'M A T É R I A S - P R I M A S'); 

Follow the Wiki link for more information: Fpspreadsheet Wiki

Browser other questions tagged

You are not signed in. Login or sign up in order to post.