Saves changes to the workbook in a different file or stream. Returns 1 if it succeeds.
function SaveAs(FileName: WideString): integer;
function SaveAs(FileName: WideString; FileFormat: TXLSFileFormat): integer;
function SaveAs(Stream: TStream);
function SaveAs(Stream: TStream; FileFormat: TXLSFileFormat): integer;
| 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. |
This example creates a new workbook with one worksheet and then saves the workbook.
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.htm', 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;
This example saves workbook into the BLOB field.
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;