Table of Contents

Class XlsxToCsvConverter

Namespace
DocToolkit
Assembly
DocToolkit.dll

Exports one sheet of a workbook as CSV (RFC 4180).

public static class XlsxToCsvConverter
Inheritance
XlsxToCsvConverter
Inherited Members

Remarks

The output does not depend on the machine's regional settings. That is a correctness requirement here rather than a preference: ReadSheet renders a number through CurrentCulture, which turns 1234.5 into 1234,5 on a German machine — a decimal comma inside a comma-delimited file. Measured across en-US, de-DE and fr-FR before this class was written. Numbers are invariant, dates are ISO 8601, and a formula cell exports its computed value.

One sheet, named explicitly. CSV has no concept of a workbook, so there is nothing sensible to do with the other sheets and no default worth guessing — SheetNames(byte[]) lists them.

Methods

Convert(byte[], string)

Exports sheetName as CSV.

public static string Convert(byte[] xlsx, string sheetName)

Parameters

xlsx byte[]

The workbook to read.

sheetName string

The sheet to export.

Returns

string

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 CSV.

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.