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 Examle1.html file with two Worksheets which contain data from DBGrid1 and DBGrid2.

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

  //First dbgrid
  GridToXLS1.WorksheetName := 'DBGrid1 sheet'; //Specifies the name for first Worksheet
  GridToXLS1.DBGrid := DBGrid1; //Specifies the dbgrid for export
  GridToXLS1.ExportDBGrid;

  //Second dbgrid
  GridToXLS1.WorksheetName := 'DBGrid2 sheet'; //Specifies the name for second Worksheet
  GridToXLS1.DBGrid := DBGrid2; //Specifies the dbgrid for export
  GridToXLS1.ExportDBGrid;

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