HotXLS Docs

SaveAs method

把工作簿保存到指定文件。成功时返回 1。以 结尾的文件名 .xlsx are written through the XLSX export bridge; .xls, .html, and .rtf continue to use the classic exporters

语法

function SaveAs(Filename: WideString): Integer;
FileName WideString。指示要保存的文件名的字符串。可以包含完整路径;如果不包含,组件会将文件保存在当前文件夹中

示例

此示例创建 Example1.xls 工作簿和 Examle1.html 文件,其中两个工作表分别包含来自 DBGrid1 和 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.xlsx'); //Saves the created Workbook into Example1.xlsx 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;