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

SaveAs method

Saves the Workbook to the specified file. Returns 1 if it succeeds.

Syntax

function SaveAs( Filename: WideString): 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, component saves the file in the current folder.

Example

This example creates Example1.xls Workbook and Example1.html with two Worksheets which contain data from Table1 and Table2 datasets.

begin
  DataToXLS1.Workbook := nil; //Clears Workbook

  //First dataset
  DataToXLS1.WorksheetName := 'Table1 sheet'; //Specifies the name for first Worksheet
  DataToXLS1.Dataset := Table1; //Specifies the dataset for export
  DataToXLS1.ExportDataset;

  //Second dataset
  DataToXLS1.WorksheetName := 'Table2 sheet'; //Specifies the name for second Worksheet
  DataToXLS1.Dataset := Table2; //Specifies the dataset for export
  DataToXLS1.ExportDataset;

  DataToXLS1.SaveAs('Example1.xls'); //Saves the created Workbook into Example1.xls file
  DataToXLS1.SaveAs('Example1.html'); //Saves the created Workbook into Example1.html file
  DataToXLS1.SaveAs('Example1.rtf'); //Saves the created Workbook into Example1.rtf file
end;
Copyright©2007-2019 loslab.com