Class XlsxToHtmlConverter
- Namespace
- DocToolkit
- Assembly
- DocToolkit.dll
Exports one sheet of a workbook as an HTML table.
public static class XlsxToHtmlConverter
- Inheritance
-
XlsxToHtmlConverter
- Inherited Members
Remarks
A fragment, not a document — a bare <table> with no <html>
wrapper, deliberately the opposite of DocxToHtmlConverter. A sheet is a component
of a page rather than a page, so the common case is embedding it; wrapping is one line for a
caller who wants a whole document, while unwrapping means parsing HTML.
Cell text is culture-invariant, matching XlsxToCsvConverter so the two exporters cannot disagree about what a cell says. See ReadSheet(byte[], string) for why that differs from reading a sheet as data.
Every cell is escaped. A workbook is untrusted input: a cell containing
<script> must arrive as text, not as markup.
Methods
Convert(byte[], string)
Exports sheetName as an HTML <table> fragment.
public static string Convert(byte[] xlsx, string sheetName)
Parameters
Returns
Remarks
The sheet's first row becomes <th> cells inside a <thead>. That is
a presentation guess — a spreadsheet does not record whether its first row is a header — and
it is the guess that is right far more often than not. A caller who disagrees can restyle
or replace the element; the alternative, emitting no header at all, cannot be undone from
the output.
Exceptions
- ArgumentNullException
xlsxis null.- ArgumentException
xlsxis empty, orsheetNameis blank.- DocumentConversionException
The workbook could not be opened, or the sheet does not exist.
ConvertAsync(Stream, string, CancellationToken)
Reads a workbook from source and exports sheetName as
an HTML <table> fragment.
source is read to its end and is neither disposed, closed nor
sought, so it may be forward-only.
public static Task<string> ConvertAsync(Stream source, string sheetName, CancellationToken ct = default)
Parameters
sourceStreamThe stream the workbook is read from.
sheetNamestringThe sheet to export.
ctCancellationTokenCancels the read.
Returns
Exceptions
- ArgumentNullException
sourceis null.- ArgumentException
sourceis not readable or held no bytes, orsheetNameis blank.- OperationCanceledException
ctwas cancelled.- DocumentConversionException
The workbook could not be opened, or the sheet does not exist.