HotXLS Docs

TXLSHTMLExport class

Unit: lxHTML
Provides direct control over the classic XLS HTML exporter. Workbook, worksheet, and range SaveAsHTML helpers use the same renderer with default settings; create TXLSHTMLExport yourself when HTML options need to be customised.

Declaration

TXLSHTMLExportOption = (xhHyperlinks, xhComments);
TXLSHTMLExportOptions = set of TXLSHTMLExportOption;

TXLSHTMLExport = class
  constructor Create;
  destructor Destroy; override;

  property Options: TXLSHTMLExportOptions;
  property CellPadding: Integer;
  property CellSpacing: Integer;
  property SimpleExport: Boolean;
  property TableBorderWidth: Integer;
  property Title: WideString;

  function SaveAsHTML(Worksheet: IXLSWorksheet; FileName: WideString): Integer; overload;
  function SaveAsHTML(Worksheet: IXLSWorksheet; Stream: TStream): Integer; overload;
  function SaveAsHTML(Range: IXLSRange; FileName: WideString): Integer; overload;
  function SaveAsHTML(Range: IXLSRange; Stream: TStream): Integer; overload;
  function SaveAsHTML(WorkBook: TXLSWorkbook; FileName: WideString): Integer; overload;
end;

Members

Member Description
Options Controls optional cell metadata in styled output. The default is [xhHyperlinks, xhComments]. Remove xhHyperlinks to export linked cells as plain text, or remove xhComments to suppress comment text in table-cell title attributes.
Title Optional HTML document title. The value is escaped before it is written to the <title> element.
SimpleExport When True, writes a minimal HTML table without generated CSS classes, hyperlink anchors, or comment title attributes. Cell display text and merged-cell spans are still escaped and preserved.
TableBorderWidth / CellPadding / CellSpacing Control the generated <table> layout attributes. All three default to 0, matching the older exporter output.
SaveAsHTML Exports a workbook, worksheet, or selected range to HTML. Worksheet and range overloads can write either to a file name or to a TStream.

Output behaviour

Styled output emits an HTML document with a generated style block and table cells that reference CSS classes. Hyperlinks become escaped <a href> anchors when xhHyperlinks is enabled. Cell comments become escaped title attributes when xhComments is enabled.
Simple output is intended for email fragments, previews, and pipelines that want plain table markup. It keeps the same selected cell content and merge spans but omits the generated CSS class system.

Example

var
  Exporter: TXLSHTMLExport;
begin
  Exporter := TXLSHTMLExport.Create;
  try
    Exporter.Title := 'Quarterly report';
    Exporter.TableBorderWidth := 1;
    Exporter.CellPadding := 4;
    Exporter.CellSpacing := 0;
    Exporter.Options := [xhHyperlinks];
    Exporter.SaveAsHTML(Workbook.Sheets[1].Range['A1', 'F20'],
      'report.html');
  finally
    Exporter.Free;
  end;
end;

See also