A very basic and simple way to get data into or out of a spreadsheet is
just to write out your data as a CSV (comma separated variables) file.
For more details about CSV files search the web or see here:
http://en.wikipedia.org/wiki/Comma-separated_values 

Write your data out as a text file, with file type = CSV. Write it line
by line, and within each line, each cell is separated by commas, and
text is enclosed with double quotes.

Save this file and then open it using the ShellExecute API call, which
opens the file in the registered application for CSV files - this will
be EXCEL in your case.  

One benefit of this very simple technique is that it works for any
spreadsheet application (yes, a few people still use Lotus 123!).

Here's some rough code:

Uses ShellAPI;   // Must add this to your units uses statement.

// NB This is ancient code - originally written in Turbo Pascal days!
//  Nowadays I'd build up the output in a stringlist.

Var OutF  : TextFile;   // Output file
    OutFn;
// Assign the file name to OutFn.
 
OutFn:='path\name.csv';  // Any path\name you like - need write
permission.
AssignFile (OutF,OutFn);
Rewrite (OutF);          // I've removed error checking code.

// Repeat something like this for each line in spreadsheet...
Writeln(OutF,'1,"'+Surname+'",'+Format('%d,%f',[Days,Payment])+
',"'+Address+'"');   

CloseFile(OutF);
// Open file in Excel or whatever is registered to open CSV files
  ShellExecute(0,'open',PChar(OutFn),nil,nil,sw_ShowNormal);

This will show the Excel window, but look up the API, as I think you can
hide it.

Now save the data back again as a CSV file, and now you can read the
lines back into variables.  You usually get warning messages when saving
as a CSV file as you lose data formatting eg column widths.

There are many variants on this technique, of course.

Regards,
       Brendan.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of CRQ
Sent: 11 August 2007 14:43
To: [email protected]
Subject: About excel automation

Hi,
I use delphi 6. From my app, I need to open an excel workbook and edit
some
data. Not necesary to show the excel window.
¿some example code?
Thanks
cr

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to