Overview

The GridX Export Engine provides a pluggable, extensible export architecture that supports multiple output formats from any BeepGridPro instance. Three formats are built-in (CSV, JSON, HTML), while Excel and PDF are provided as stubs that can be replaced by external plugins discovered at runtime via assembly scanning.

The engine is accessible via grid.ExportEngine (an instance of GridExportEngine). It supports output to file, Stream, or string, and respects grouping, filtering, column visibility, and selection state.

GridExportEngine

The GridExportEngine class manages the registry of exporters and coordinates the export pipeline. It provides methods for registration, querying available formats, and performing exports.

MemberSignature / TypeDescription
RegisteredFormatsProperty: IReadOnlyList<string>List of currently registered format names (e.g., "Csv", "Json")
RegisteredExportersProperty: IReadOnlyDictionary<string, IGridExporter>Format name to exporter instance mapping
Registervoid Register(string format, IGridExporter exporter)Registers a new exporter; overrides any existing exporter for the same format
Unregistervoid Unregister(string format)Removes an exporter by format name
IsRegisteredbool IsRegistered(string format)Checks if an exporter is registered for the given format
IsAvailablebool IsAvailable(string format)Returns true if registered AND the exporter's IsAvailable property is true
GetExporterIGridExporter GetExporter(string format)Retrieves the exporter instance for a format; returns null if not registered
ExportToFilevoid ExportToFile(string format, string filePath, ExportOptions options = null)Exports grid data to a file on disk
ExportToStreamvoid ExportToStream(string format, Stream stream, ExportOptions options = null)Exports grid data to a writable Stream
ExportToStringstring ExportToString(string format, ExportOptions options = null)Exports grid data and returns it as a string
DiscoverPluginsvoid DiscoverPlugins()Scans all loaded assemblies for IGridExporter implementations and replaces stubs

Export Formats

FormatExtensionTypeExporter ClassDescription
CSV.csvBuilt-inGridCsvExporterComma-separated values with configurable delimiter and quoting
Json.jsonBuilt-inGridJsonExporterIndented JSON array of objects with property-name keys
Html.htmlBuilt-inGridHtmlExporterFull HTML document with styled table and embedded CSS
Excel.xlsxStub / PluginGridExcelStubExporterStub throws NotSupportedException; replace with plugin (e.g., EPPlus/ClosedXML)
Pdf.pdfStub / PluginGridPdfStubExporterStub throws NotSupportedException; replace with plugin (e.g., iTextSharp/QuestPDF)

IGridExporter Interface

All exporters implement IGridExporter. Custom exporters can be created by implementing this contract and registering via Register().

public interface IGridExporter
{
    string Format { get; }
    string Description { get; }
    string FileExtension { get; }
    bool IsAvailable { get; }

    void Export(BeepGridPro grid, Stream stream, ExportOptions options);
}
MemberTypeDescription
FormatstringUnique format name (e.g., "Csv", "Json", "Excel")
DescriptionstringHuman-readable description shown in UI dialogs
FileExtensionstringDefault file extension including dot (e.g., ".csv")
IsAvailableboolTrue if the exporter is ready; stub exporters return false
ExportMethodCore export logic: reads grid data and writes formatted output to the stream

Built-in Exporters

GridCsvExporter

Produces RFC 4180-compliant CSV. Honors ExportOptions.Delimiter (default comma), ExportOptions.IncludeHeaders (first row = column names), and ExportOptions.QuoteAllStrings. Uses double-quote escaping for values containing the delimiter, quotes, or newlines.

GridJsonExporter

Produces a valid JSON array of objects. Uses Newtonsoft.Json internally. Each row becomes a JSON object with column names as property names. Honors ExportOptions.IndentSpaces for pretty-printing (default 2). Supports ExportOptions.IncludeHiddenColumns and ExportOptions.NullValueRepresentation.

GridHtmlExporter

Produces a complete self-contained HTML document with embedded CSS styling. The table inherits the grid's visual theme colors. Includes a <thead> section, striped rows, and responsive styling. Honors ExportOptions.IncludeGroupHeaders to render group header rows as <tr class="group-header">.

Plugin Discovery

DiscoverPlugins() scans all assemblies loaded in the current AppDomain for types implementing IGridExporter. When a matching exporter is found, it replaces the corresponding stub in the registry. This enables drop-in Excel/PDF support:

grid.ExportEngine.DiscoverPlugins();

bool excelReady = grid.ExportEngine.IsAvailable("Excel");
if (excelReady)
{
    grid.ExportEngine.ExportToFile("Excel", @"C:\reports\data.xlsx");
}

The discovery method uses Assembly.GetTypes() wrapped in try/catch to handle ReflectionTypeLoadException — if an assembly fails to load its types (e.g., missing dependencies), it is silently skipped. This ensures that plugin discovery never crashes the host application.

ExportOptions

ExportOptions provides fine-grained control over export output. An instance is passed to each Export* method; if null, sensible defaults are used.

PropertyTypeDefaultDescription
Delimiterstring","Field separator for CSV (e.g., ";" for semicolon, "\t" for TSV)
IndentSpacesint2Indentation spaces for JSON pretty-printing
IncludeHiddenColumnsboolfalseWhen false, hidden columns are excluded from output
VisibleOnlyboolfalseWhen true, only currently visible rows (post-filter) are exported
IncludeGroupHeadersbooltrueIncludes group header rows in CSV/HTML output
DateFormatstring"yyyy-MM-dd"Format string for DateTime values
NullValueRepresentationstring""String to emit for null/DBNull values
IncludeHeadersbooltrueWhether column headers are included as the first row/entry
QuoteAllStringsboolfalseCSV only: wraps all string values in double quotes

Examples

Export to CSV File

var engine = grid.ExportEngine;

engine.ExportToFile("Csv", @"C:\exports\data.csv", new ExportOptions
{
    Delimiter = ",",
    IncludeHeaders = true,
    NullValueRepresentation = "N/A"
});

Export to JSON String

var engine = grid.ExportEngine;

string json = engine.ExportToString("Json", new ExportOptions
{
    IndentSpaces = 4,
    IncludeHiddenColumns = false,
    DateFormat = "yyyy-MM-ddTHH:mm:ss"
});

File.WriteAllText(@"C:\exports\data.json", json);

Stream Export for Web Response

using (var ms = new MemoryStream())
{
    grid.ExportEngine.ExportToStream("Csv", ms);
    ms.Position = 0;

    var response = HttpContext.Current.Response;
    response.ContentType = "text/csv";
    response.AddHeader("Content-Disposition", "attachment; filename=data.csv");
    ms.CopyTo(response.OutputStream);
}

Plugin Discovery + Excel Export

var engine = grid.ExportEngine;
engine.DiscoverPlugins();

if (engine.IsRegistered("Excel") && engine.IsAvailable("Excel"))
{
    engine.ExportToFile("Excel", @"C:\reports\summary.xlsx", new ExportOptions
    {
        DateFormat = "MM/dd/yyyy",
        NullValueRepresentation = "-"
    });
}
else
{
    engine.ExportToFile("Csv", @"C:\reports\summary.csv");
}