Table of Contents

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

xlsx byte[]

The workbook to read.

sheetName string

The sheet to export.

Returns

string

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

xlsx is null.

ArgumentException

xlsx is empty, or sheetName is 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

source Stream

The stream the workbook is read from.

sheetName string

The sheet to export.

ct CancellationToken

Cancels the read.

Returns

Task<string>

Exceptions

ArgumentNullException

source is null.

ArgumentException

source is not readable or held no bytes, or sheetName is blank.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The workbook could not be opened, or the sheet does not exist.