| FileName | WideString. A string that indicates the name of the file to be saved. You can include a full path; if you don't, Workbook saves the file in the current folder |
| FileFormat | Optional TXLSFileFormat. A value that indicates format of the file to be saved. Default is xlExcel97 |
| Stream | TStream. Saves Workbook to a stream specified in the Stream parameter |
XLS file output completes serialization in a sibling staging file before replacing the destination; a failed commit leaves the existing destination intact and reports the captured native error through the workbook diagnostics
On Windows filesystems supporting POSIX rename, replacement can succeed while a metadata or reader handle that allows deletion remains open; an existing reader continues to see the original file object, and a new reader of the destination name sees the completed replacement
The destination must permit delete access and delete sharing, and readonly targets still reject; a failed commit is not retried, while missing targets, reparse paths and unsupported filesystems use the legacy commit path selected before replacement
Atomic replacement protects the publication of one completed file; it does not provide compare-and-swap isolation against another process concurrently replacing the same name
| xlExcel97 | MS Excel 97,2000,XP,2003 file format |
| xlExcel5 | MS Excel 5,95 file format |
| xlHTML | HTML file format |
| xlRTF | Rich Text Format (RTF) |
| xlCSV | Comma separated values file format (CSV) |
| xlText | Tab separated values file format (TSV) |
| xlUnicodeCSV | Comma separated unicode values file format (CSV) |
| xlUnicodeText | Tab separated unicode values file format (TSV) |
Var
Workbook: IXLSWorkbook;
begin
Workbook := TXLSWorkbook.Create; {create new Workbook}
Workbook.Worksheets.Add;
{...}
//Save Workbook as Excel 97 file format
Workbook.SaveAs('C:\book.xls');
//Save Workbook as Excel 5-95 file format
Workbook.SaveAs('C:\book5.xls', xlExcel5);
//Save Workbook as HTML
Workbook.SaveAs('C:\book.html', xlHTML);
//Save Workbook as RTF file
Workbook.SaveAs('C:\book.rtf', xlRTF);
//Save active Worksheet as comma separated values (CSV)
Workbook.SaveAs('C:\book.csv', xlCSV);
//Save active Worksheet as tab separated values (TSV)
Workbook.SaveAs('C:\book.tsv', xlText);
//Save active Worksheet as comma separated unicode values (CSV)
Workbook.SaveAs('C:\book.csv', xlUnicodeCSV);
//Save active Worksheet as tab separated unicode values (TSV)
Workbook.SaveAs('C:\book.tsv', xlUnicodeText);
end;
var
MS: TMemoryStream;
begin
if not (ClientDataSet1.State in [dsInsert, dsEdit]) then
ClientDataSet1.Insert;
MS := TMemoryStream.Create();
try
FWorkbook.SaveAs(MS);
ClientDataSet1Documents.LoadFromStream(MS);
finally
MS.Free;
end;
ClientDataSet1.Post;
end;