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