[]
Imports data from a data source (up to 2D) to the range.
DataImportResult ImportData(IEnumerable items, DataImportOptions options = null)
Function ImportData(items As IEnumerable, Optional options As DataImportOptions = Nothing) As DataImportResult
| Type | Name | Description |
|---|---|---|
| IEnumerable | items | The items to import. The element type can be:
If the item collection is a list of primitive types, the orientation is determined by the shape of range. If the row count of the range is greater than column count, we import the collection vertically. Otherwise, we import the collection horizontally. |
| DataImportOptions | options | The import options. |
| Type | Description |
|---|---|
| DataImportResult | A DataImportResult that describes the imported rows and columns. |
Dictionary<string, object> item = new Dictionary<string, object>();
item["Name"] = "Alice";
item["Score"] = 95;
DataImportOptions options = new DataImportOptions();
options.ColumnsSelector = source => new string[] {"Name"};
DataImportResult result = worksheet.Range["A1"].ImportData(new[] {item}, options);
int columnsImported = result.ColumnsImported;
| Type | Condition |
|---|---|
| InvalidCastException | The data type of a column is inconsistent. Use ItemTypeProvider to fix it. |
| ArgumentException | An item is of an unsupported type or |
| NotSupportedException | It's typically thrown when AOT compatibility issues occur at runtime. |
Imports data from a data source (up to 2D) to the range.
DataImportResult ImportData<T>(IEnumerable<T> items, DataImportOptions options = null)
Function ImportData(Of T)(items As IEnumerable(Of T), Optional options As DataImportOptions = Nothing) As DataImportResult
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | items | The items to import. The element type can be:
If the item collection is a list of primitive types, the orientation is determined by the shape of range. If the row count of the range is greater than column count, we import the collection vertically. Otherwise, we import the collection horizontally. |
| DataImportOptions | options | The import options. |
| Type | Description |
|---|---|
| DataImportResult |
| Name | Description |
|---|---|
| T |
var items = new[] {new SalesRecord { Name = "Alice", Score = 95 }};
DataImportResult result = worksheet.Range["A1"].ImportData(items);
int rowsImported = result.RowsImported;
| Type | Condition |
|---|---|
| InvalidCastException | The data type of a column is inconsistent. Check whether the implementation of ItemTypeProvider is correct. |
| ArgumentException | An item is of an unsupported type or |
| NotSupportedException | It's typically thrown when AOT compatibility issues occur at runtime. |
Imports data from a table to the range.
DataImportResult ImportData(DataTable table, DataImportOptions options = null)
Function ImportData(table As DataTable, Optional options As DataImportOptions = Nothing) As DataImportResult
| Type | Name | Description |
|---|---|---|
| DataTable | table | The table to import. The column type can be: |
| DataImportOptions | options | The import options. |
| Type | Description |
|---|---|
| DataImportResult | A DataImportResult that describes the imported rows and columns. |
DataTable table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Score", typeof(int));
table.Rows.Add("Alice", 95);
DataImportOptions options = new DataImportOptions();
options.IncludeColumnsHeader = true;
DataImportResult result = worksheet.Range["A1"].ImportData(table, options);
int columnsImported = result.ColumnsImported;
| Type | Condition |
|---|---|
| InvalidCastException | The data type of a column is inconsistent. |
| ArgumentException |
|
| NotSupportedException | It's typically thrown when AOT compatibility issues occur at runtime. |