Page 1 of 1

exporting to excel

Posted: Tue Nov 02, 2004 11:43 am
by 9337879
Hi!

I want to export the data in a chart to excel. I use this code:

with TSeriesDataXLS.Create(chart1,nil) do
try
includeindex:=true;
IncludeHeader := True;
IncludeLabels := True;
CopyToClipboard;
finally
Free;
end;

but it doesn't work. When I paste in Excel I get empty cells. The number of empty cells differs so it does something. If my piechart for instance has 4 pieces I get 4 empty cells and so on.

If I change "CopyToClipboard;" to "SaveToFile('c:\test.xls');" it works but
I would like to avoid the actual excel-file. The users of my application have to be able to copy the chart-data into an existing excel document.

What do I do wrong?

/Patrik

Posted: Tue Nov 02, 2004 4:02 pm
by Pep
Hi Patrik,

to do a copy/paste of the data to Excel file you must export the data as text to a ClipBoard and then you will be able to paste it on excel sheet.

Posted: Wed Nov 03, 2004 8:55 am
by 9337879
Thanks for ur answer, but how do I do that? I thought the CopyToClipboard command did exactly that.

Some example code or a link do some other help would be much appreciated.

Thanks in advance.

Posted: Wed Nov 03, 2004 11:22 am
by Pep
Hi Patrik,

you can use the following code :

Code: Select all

     with TSeriesDataText.Create(Chart1,nil) do
     try
       TextDelimiter:=',' ;  { try also: TeeTabDelimiter }
       IncludeIndex:=true;
       CopyToClipBoard;
     finally
       Free;
     end;