TOExporterXLSX

TCustomExporterTOExporterXLSX

Description

TOExporterXLSX is the XLSX document generation class.

Properties

TOExporterXLSX does not have any special properties.

TOExporterXLTX

TCustomExporterTOExporterXLSXTOExporterXLTX

Description

TOExporterXLTX is the XLTX document generation class. It generates templates for XLSX/Excel 2007.

This exporter is not registered by default because your users usually don't want to save documents from your applications as templates. In order to create an XLTX template and open it in Excel as a new document without name, use this code:

uses ComObj;

procedure TForm1.BtnCreateTemplateClick(Sender: TObject);
var
  xExport: TOExport;
  xExporter: TOCustomExporter;
  xExcelApp: OleVariant;
const
  xFileName = 'hello.xltx';//USE YOUR OWN TEMPORARY FILE
begin
  xExport := TOExport.Create;
  try
    //FILL WorkSheet with data
    xExport.AddWorkSheet('Hello').AddRow.AddCellString('Hello');


    //Export as template
    xExporter := TOExporterXLTX.Create;
    try
      xExport.SaveToFile(xFileName, xExporter, False);
    finally
      xExporter.Free;
    end;

    //open Excel window
    try
      xExcelApp := GetActiveOleObject('Excel.Application');
    except
      try
        // If no instance of Excel is running, try to Create a new Excel Object
        xExcelApp := CreateOleObject('Excel.Application');
      except
        ShowMessage('Cannot start Excel/Excel not installed ?');
        Exit;
      end;
    end;

    xExcelApp.Workbooks.Open(xFileName);
    xExcelApp.Visible := True;

    //DELETE TEMPORARY TEMPLATE
    DeleteFile(xFileName);
  finally
    xExport.Free;
  end;
end;
Categories