Table of Contents

Method ImportData

Namespace
DocWright.Spreadsheet
Assembly
DocWright.Spreadsheet.dll

ImportData(DataTable, int, int, XlsxImportOptions?)

Writes a table into the sheet: one row for each of its rows, one column for each of its columns.

public XlsxCellRange? ImportData(DataTable table, int row, int column, XlsxImportOptions? options = null)

Parameters

table DataTable

The table. It is read, not kept.

row int

The one-based row of the first cell written.

column int

The one-based column of the first cell written.

options XlsxImportOptions

The options, or null for the defaults: a header row, dates shown as yyyy-mm-dd, every column.

Returns

XlsxCellRange?

The range written, header included; null when nothing was written (no columns, or no rows and no header).

Remarks

Every value becomes a typed cell, and none is reinterpreted. A string is text: one that starts with = is not a formula and one that looks like a number or a date stays the text it is (Excel, given the same strings through automation, converts them; measured). Whole numbers and decimals keep every digit; a float is the number it stands for; a date is stored in the workbook's own date system and shown through DateFormat where the cell does not already show dates; a TimeSpan is a number of days shown as [h]:mm:ss; a Guid, a character and an enum's name are text; null and DBNull empty the cell.

The cells are changed as SetValue(int, int, XlsxCellValue) changes them, one edit each, and the same cells are refused. Nothing is calculated. When an import is refused part of the way, the rows already written stay written.

Exceptions

ArgumentNullException

table is null.

ArgumentOutOfRangeException

The first cell is outside the worksheet grid.

ArgumentException

The data does not fit the grid from that cell; Columns names a column the table lacks; or a value is of a type a cell cannot hold, or is more than 32,767 characters of text (the message names the row and the column).

ResourceLimitExceededException

The table has more rows than MaxRows.

InvalidOperationException

The sheet is not a worksheet.

UnsupportedFeatureException

A cell in the way is part of an array formula entered over several cells, or is a header or totals cell of a table.

InvalidDocumentException

The sheet's part is malformed.

ImportData(DataView, int, int, XlsxImportOptions?)

Writes a view of a table into the sheet: the rows the view shows, in the view's order. See ImportData(DataTable, int, int, XlsxImportOptions?) for how values are written.

public XlsxCellRange? ImportData(DataView view, int row, int column, XlsxImportOptions? options = null)

Parameters

view DataView

The view. It is read, not kept.

row int

The one-based row of the first cell written.

column int

The one-based column of the first cell written.

options XlsxImportOptions

The options, or null for the defaults.

Returns

XlsxCellRange?

The range written, header included; null when nothing was written.

Exceptions

ArgumentNullException

view is null.

ArgumentOutOfRangeException

The first cell is outside the worksheet grid.

ArgumentException

The view has no table; the data does not fit the grid; a named column is missing; or a value cannot be held by a cell.

ResourceLimitExceededException

The view has more rows than MaxRows.

InvalidOperationException

The sheet is not a worksheet.

UnsupportedFeatureException

A cell in the way cannot have its content changed.

InvalidDocumentException

The sheet's part is malformed.

ImportData<T>(IEnumerable<T>, int, int, XlsxImportOptions?)

Writes a sequence of items into the sheet: one row for each item, one column for each public readable property whose type a cell can hold (or the ones Columns names). A sequence of plain values, such as numbers or strings, is one column headed Value. See ImportData(DataTable, int, int, XlsxImportOptions?) for how values are written.

public XlsxCellRange? ImportData<T>(IEnumerable<T> items, int row, int column, XlsxImportOptions? options = null)

Parameters

items IEnumerable<T>

The items. The sequence is gone through once.

row int

The one-based row of the first cell written.

column int

The one-based column of the first cell written.

options XlsxImportOptions

The options, or null for the defaults.

Returns

XlsxCellRange?

The range written, header included; null when nothing was written.

Type Parameters

T

The type of the items. Its properties are found once and kept for the type.

Exceptions

ArgumentNullException

items is null.

ArgumentOutOfRangeException

The first cell is outside the worksheet grid.

ArgumentException

T has no property a cell can hold; a named property is missing or of a type a cell cannot hold; the data does not fit the grid; or a value cannot be held by a cell.

ResourceLimitExceededException

The sequence has more items than MaxRows.

InvalidOperationException

The sheet is not a worksheet.

UnsupportedFeatureException

A cell in the way cannot have its content changed.

InvalidDocumentException

The sheet's part is malformed.

ImportData(object?[,], int, int, XlsxImportOptions?)

Writes a two-dimensional array into the sheet: its first dimension down the rows, its second across the columns. An array has no names, so no header row is written and Columns must be empty. See ImportData(DataTable, int, int, XlsxImportOptions?) for how values are written.

public XlsxCellRange? ImportData(object?[,] values, int row, int column, XlsxImportOptions? options = null)

Parameters

values object[,]

The values. The array is read, not kept.

row int

The one-based row of the first cell written.

column int

The one-based column of the first cell written.

options XlsxImportOptions

The options, or null for the defaults.

Returns

XlsxCellRange?

The range written; null when the array has no rows or no columns.

Exceptions

ArgumentNullException

values is null.

ArgumentOutOfRangeException

The first cell is outside the worksheet grid.

ArgumentException

Columns is not empty; the array does not fit the grid; or a value cannot be held by a cell.

ResourceLimitExceededException

The array has more rows than MaxRows.

InvalidOperationException

The sheet is not a worksheet.

UnsupportedFeatureException

A cell in the way cannot have its content changed.

InvalidDocumentException

The sheet's part is malformed.