TOExporterXLS

TCustomExporterTOExporterXLS

Description

TOExporterXLS is the XLS document generation class.

Properties

TOExporterXLS does not have any special properties.

Limitations

TOExporterXLS cannot export the following properties (in version 2.10):

  1. Images
  2. Charts

TOExporterXLT

TCustomExporterTOExporterXLSTOExporterXLT

Description

TOExporterXLT is the XLT document generation class. It generates templates for XLS/Excel 97-2003.

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 XLT 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.xlt';//USE YOUR OWN TEMPORARY FILE
begin
  xExport := TOExport.Create;
  try
    //FILL WorkSheet with data
    xExport.AddWorkSheet('Hello').AddRow.AddCellString('Hello');


    //Export as template
    xExporter := TOExporterXLT.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