Clientdataset for Excel

Asked

Viewed 220 times

0

I’m exporting a clientdataset for excel with the Clientdatasettoexcelfile function, but one of the information is CPF/CNPJ ex: 00112312312, that is, it contains zeros(0) at the beginning of the string. When exporting excel ends up removing these characters because the cell is of the GENERAL type as default.

Here I feed the cell:

Excel.WorkBooks[1].Sheets[iSheet].Cells[eline,(vCol+1)] := pQr.Fields[i].AsString;

I tried to use the following instruction:

Excel.WorkBooks[1].Sheets[iSheet].Cells[eline,(vCol+1)].NumberFormat := '@';

In excel works, but in my case replaced the values by "64" and logically worked nothing.

I use Delphi XE...

Any hint?

2 answers

1


Good morning henriquew.. Everything straight?? :)
Dude I think just change the ORDER of commands..
First Voce FORMAT THE CELL

ObjetoExcelApplication.Range[Cel,Cel].NumberFormat:= '@';<br>

Then you put the value in it

ObjetoExcelApplication.Range[Cel,Cel].Value := Texto;

It worked here..
Try it and see if it works :)

  • Buenas Ricardo, actually in my example I tried to change the order, but it did not work, always it replaces the value of the cell by 64, I believe it is the ascii value of @... you use Delphi XE also?

  • Falaaaa..: ).. Cara testei com DELPHI 7 .. Na Maquina Virtual que tenho o Delphi CE instalado, não tem ofice.. :(

  • I’ve had this problem. Excel displays 64, but if you specify another format, the content is correct. I usually include an apostrophe starting the content to stay as text.

0

Excel.WorkBooks[1].Sheets[iSheet].Cells[eline,(vCol+1)].NumberFormat := 'Texto';
Excel.WorkBooks[1].Sheets[iSheet].Cells[eline,(vCol+1)] := pQr.Fields[i].AsString;

Browser other questions tagged

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