HotXLS Delphi Excel Read Write Library / Component Developers Guide loslab Inc.

SaveAs method

Saves changes to the Workbook in a different file or stream. Returns 1 if it succeeds.

Syntax

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.

Description

FileFormat can be one of these TXLSFileFormat constants.
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)

Example

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.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;
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;
Copyright©2007-2019 loslab.com