Table of Contents

TAdvGridExcelExport.Export Method

Overloads

TAdvGridExcelExport.Export(TFileName, string)

Exports the attached grid or workbook to Excel.

Remarks

For more flexibility in how to generate the file use Export(TExcelFile, TInsertInSheet) instead.

Syntax

Unit: UAdvGridExcelExport

procedure TAdvGridExcelExport.Export(const FileName: TFileName; const SheetName: string); overload;

Parameters

<-> Parameter Type Description
const FileName TFileName Filename of the generated file. If the extension is "xls" then the file will be saved as Excel 2003, if it is xlsx/xlsm it will be saved as Excel 2007.
const SheetName string Defines the sheet name for the exported file. If empty, a normal "Sheet1" will be used.

See also

TAdvGridExcelExport.Export(TExcelFile, TInsertInSheet)

Exports the grid into an existing TExcelFile object. You can use this method to add the grid to existing files. Once the file is exported, you can use TExcelFile.Save(string) to save the file.

Syntax

Unit: UAdvGridExcelExport

procedure TAdvGridExcelExport.Export(const Xls: TExcelFile; const InsertInSheet: TInsertInSheet = TInsertInSheet.Clear); overload;

Parameters

<-> Parameter Type Description
const Xls TExcelFile TExcelFile containing the Excel file where the grid will be exported.
const InsertInSheet TInsertInSheet Optional: Default value is TInsertInSheet.Clear

How the grid will be inserted in the existing file.

Examples

To export the grid to an existing file, you can use the code:

uses ..., FlexCel.Core, FlexCel.XlsAdapter;
...
procedure TExampleForm.ExportGrid;
var
  xls: TExcelFile;
begin
  //Let's create an empty file. We could also open a template
  xls := TXlsFile.Create(1, TExcelFileFormat.v2019, true);
  try
    //Export the grid to the xls object.
    AdvGridExcelExport1.Export(xls);

    //Now you can do extra stuff with the xls file.
    //Adding rows, setting options, adding sheets
    //And exporting other grids.

    xls.PageHeader := '&CThis is a header';

    // Finally save the xls object to a real file.
    xls.Save('MyFile.xlsx');

  finally
    xls.Free;
  end;
end;

See also

TAdvGridExcelExport.Export(TStream, TFileFormats, string)

Exports the attached grid or workbook to Excel.

Remarks

For more flexibility in how to generate the file use Export(TExcelFile, TInsertInSheet) instead.

Syntax

Unit: UAdvGridExcelExport

procedure TAdvGridExcelExport.Export(const aStream: TStream; const SaveFormat: TFileFormats; const SheetName: string); overload;

Parameters

<-> Parameter Type Description
const aStream TStream Stream where the selected file will be saved.
const SaveFormat TFileFormats Format in which to save the file. As we are saving to a stream and there is no filename we can't figure out whether to save as xls or xlsx, and you need to specify it here.
const SheetName string Defines the sheet name for the exported file. If empty, a normal "Sheet1" will be used.

See also