Class TwDataTableExport
- Namespace
- TwBlazor.Components
- Assembly
- TwBlazor.dll
Writes rows out as CSV or as an Excel workbook, using TwDataTableColumn<TItem> definitions for the headings and the values. TwDataTable<TItem> uses it for its export buttons, and it can be called on its own, for example to build a file on the server.
public static class TwDataTableExport
- Inheritance
-
TwDataTableExport
- Inherited Members
Remarks
Each cell takes the column's ExportFormatter when it has one,
then its PropertySelector, then its
CellFormatter. Columns whose Exportable
is false are left out.
Fields
CsvContentType
The media type of a CSV file.
public const string CsvContentType = "text/csv"
Field Value
ExcelContentType
The media type of an Excel workbook.
public const string ExcelContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Field Value
Methods
ToCsv<TItem>(IEnumerable<TItem>, IEnumerable<TwDataTableColumn<TItem>>)
Writes rows as CSV text, with a heading row first. Fields are quoted when they need to be,
numbers and dates are written in an invariant format so any spreadsheet reads them the same way, and text that
a spreadsheet would run as a formula is prefixed with an apostrophe.
public static string ToCsv<TItem>(IEnumerable<TItem> rows, IEnumerable<TwDataTableColumn<TItem>> columns)
Parameters
rowsIEnumerable<TItem>The rows to write.
columnsIEnumerable<TwDataTableColumn<TItem>>The columns to write, in order.
Returns
- string
The CSV text, with a line break after every row.
Type Parameters
TItemThe type of the rows.
ToExcel<TItem>(IEnumerable<TItem>, IEnumerable<TwDataTableColumn<TItem>>, string)
Writes rows as an Excel workbook with one worksheet. The heading row is bold and stays in
view as the sheet scrolls, numbers and true or false values keep their types, and dates are real dates.
public static byte[] ToExcel<TItem>(IEnumerable<TItem> rows, IEnumerable<TwDataTableColumn<TItem>> columns, string sheetName = "Sheet1")
Parameters
rowsIEnumerable<TItem>The rows to write.
columnsIEnumerable<TwDataTableColumn<TItem>>The columns to write, in order.
sheetNamestringThe name of the worksheet. Characters Excel does not allow are replaced, and the name is cut to 31 characters.
Returns
- byte[]
The contents of an
.xlsxfile.
Type Parameters
TItemThe type of the rows.