I have the following code from Mastering Delphi 6 by Marco Cantu [Page 875] as supplied in the CD supplied with the book [more particularly a Project called "Office"] which I have got to work very well in transporting data created by my Delphi 6 Application into an Excel "PivotFile". To which I relate a prepared spreadsheet of my own.
My only problems with the project are
1.
It always leaves me with only the one option of filing the created Excel file to a file called "Book1".
I would prefer to control the name of the file that Excel creates - to be something of my own choosing; but I don't see HOW to do that from the code: indeed I don't even see how it comes about that a file to be called "Book 1" is forced.
Is there some coding-genius out there who can please throw some light on this?
2
If I create a fresh file from this code from an updated version of my Paradox table in this manner the NEW Book1 will obviousely overwrite the original Book1 - so that older infomation [in the original Book1] is deleted.
I would prefer that a fresh "Book1" merely UPDATES the FIELDS in the old "Book1" - but cannot see how to bring that about.
Is there some coding-genius out there who can please throw some light on this?
Thanks in advance.
delphiman
// create and show
ExcelApplication1.Visible [0] := True;
ExcelApplication1.Workbooks.Add (NULL, 0);
// fill is the first row with field titles
RangeE := ExcelApplication1.ActiveCell;
for I := 0 to tblMyTotals.Fields.Count - 1 do
begin
RangeE.Value := tblMyTotals.Fields [I].DisplayLabel;
RangeE := RangeE.Next;
end;
// add field data in following rows
tblMyTotalsDisableControls;
try
Bookmark := MyTotals.Bookmark;
try
tblMyTotals.First;
Row := 2;
while not tblMyTotals.EOF do
begin
RangeE := ExcelApplication1.Range ['A' + IntToStr (Row),
'A' + IntToStr (Row)];
for I := 0 to tblMyTotals.Fields.Count - 1 do
begin
RangeE.Value := tblMyTotals.Fields [I].AsString;
RangeE := RangeE.Next;
end;
tblMyTotals.Next;
Inc (Row);
end;
finally
tblMyTotals.Bookmark := Bookmark;
end;
finally
tblMyTotals.EnableControls;
end;
// format the section
RangeE := ExcelApplication1.Range ['A1', 'E' + IntToStr (Row - 1)];
RangeE.AutoFormat (3, NULL, NULL, NULL, NULL, NULL, NULL);
end;