Skip to main content
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

Inline example 1PascalC++
// Save to a file
Grid.SaveToHTMLData('report.html');

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

// Save to a file with explicit encoding
Grid->SaveToHTMLData(L"report->html", TEncoding->UTF8);

Export to a stream

Inline example 2PascalC++
var Stream := TFileStream.Create('output.html', fmCreate);
try
  Grid.SaveToHTMLStreamData(Stream, TEncoding.UTF8);
finally
  Stream.Free;
end;
var Stream = TFileStream->Create(L"output->html", fmCreate);
try
  Grid->SaveToHTMLStreamData(Stream, TEncoding->UTF8);
finally
  Stream->Free;
}

Open the result in a browser

Inline example 3PascalC++
Grid.SaveToHTMLData('report.html');
ShellExecute(0, 'open', PChar(ExpandFileName('report.html')), nil, nil, SW_SHOW);
Grid->SaveToHTMLData(L"report->html");
ShellExecute(0, L"open", PChar(ExpandFileName(L"report->html")), nullptr, nullptr, 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.

Inline example 4PascalC++
// 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);
// Apply a filter so only matching rows appear in the export
Grid->ClearFilter;
with Grid->Filter->Add do { Column = 3; Condition = L"Active"; }
Grid->ApplyFilter;

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

// Hide a column before exporting, then restore it
Grid->HideColumn(0);
Grid->SaveToHTMLData(L"report-no-id->html");
Grid->UnhideColumn(0);

Combining file and stream export

The same grid often has to reach two destinations: a file the user can open in a browser and an in-memory or network stream for an email body or a web response. Both exports read what is currently visible, so configure the HTML options once and then run each export in turn. Combining the two methods is useful for a report workflow that archives a copy on disk while handing the same markup to another component. The example below enables image export, saves the grid to a UTF-8 file, writes a second copy to a file stream, and opens the first file in the default browser.

Combining file and stream exportPascalC++
procedure TForm1.ExportHTMLButtonClick(Sender: TObject);
var
  Stream: TFileStream;
begin
  // Export settings apply to both the file and the stream export
  Grid.Options.IO.HTML.ExportImages := True;

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

  // 2. Write a second copy to a stream
  Stream := TFileStream.Create('report-copy.html', fmCreate);
  try
    Grid.SaveToHTMLStreamData(Stream, TEncoding.UTF8);
  finally
    Stream.Free;
  end;

  // 3. Show the first result in the default browser
  TTMSFNCUtils.OpenFile('report.html');
end;
void __fastcall TForm1::ExportHTMLButtonClick(TObject *Sender)
{
  // Export settings apply to both the file and the stream export
  Grid->Options->IO->HTML->ExportImages = true;

  // 1. Save to a file with explicit encoding
  Grid->SaveToHTMLData("report.html", TEncoding::UTF8);

  // 2. Write a second copy to a stream
  TFileStream *Stream = new TFileStream("report-copy.html", fmCreate);
  try
  {
    Grid->SaveToHTMLStreamData(Stream, TEncoding::UTF8);
  }
  __finally
  {
    delete Stream;
  }

  // 3. Show the first result in the default browser
  TTMSFNCUtils::OpenFile("report.html");
}
  • Grid.SaveToHTMLData(AFileName)
  • Grid.SaveToHTMLData(AFileName, AEncoding)
  • Grid.SaveToHTMLStreamData(AStream)
  • Grid.SaveToHTMLStreamData(AStream, AEncoding)

See also