Table of Contents

Export (HTML)

Export the visible grid content as a self-contained HTML table to a file or stream. The output is a <table> element styled inline that faithfully reflects the column headers and data rows.

Overview

HTML export generates an HTML file directly from the grid's rendered content. It is useful for pasting grids into emails, reports, or static web pages.

Operation Method
Export to file Grid.SaveToHTMLData(FileName)
Export to file with encoding Grid.SaveToHTMLData(FileName, Encoding)
Export to stream Grid.SaveToHTMLStreamData(Stream)
Export to stream with encoding Grid.SaveToHTMLStreamData(Stream, Encoding)

Quick example

// Save to a file
Grid.SaveToHTMLData('report.html');

// Save to a file with explicit encoding
Grid.SaveToHTMLData('report.html', TEncoding.UTF8);

Export to a stream

var Stream := TFileStream.Create('output.html', fmCreate);
try
  Grid.SaveToHTMLStreamData(Stream, TEncoding.UTF8);
finally
  Stream.Free;
end;

Open the result in a browser

Grid.SaveToHTMLData('report.html');
ShellExecute(0, 'open', PChar(ExpandFileName('report.html')), nil, nil, SW_SHOW);

What is exported

  • All non-hidden columns and rows in their current display order.
  • Column header text from the fixed header row.
  • Cell text values — HTML markup stored in cells is included as-is and will render in the browser.
  • Basic cell structure; the output is a plain <table> without grid-specific CSS classes.

Fixed rows (headers) and hidden columns are handled by the export engine. The export reflects what is currently visible in the grid.

// Apply a filter so only matching rows appear in the export
Grid.ClearFilter;
with Grid.Filter.Add do begin Column := 3; Condition := 'Active'; end;
Grid.ApplyFilter;

// Export — only the rows currently visible are written to the file
Grid.SaveToHTMLData('active-records.html');

// Hide a column before exporting, then restore it
Grid.HideColumn(0);
Grid.SaveToHTMLData('report-no-id.html');
Grid.UnhideColumn(0);
  • Grid.SaveToHTMLData(AFileName)
  • Grid.SaveToHTMLData(AFileName, AEncoding)
  • Grid.SaveToHTMLStreamData(AStream)
  • Grid.SaveToHTMLStreamData(AStream, AEncoding)

See also