Back to Devexpress

TableCollection.Add(Object, CellRange) Method

officefileapi-devexpress-dot-spreadsheet-dot-tablecollection-dot-add-x28-system-dot-object-devexpress-dot-spreadsheet-dot-cellrange-x29.md

latest5.0 KB
Original Source

TableCollection.Add(Object, CellRange) Method

Creates a table from the specified range, adds it to the collection and binds it to the data source.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
Table Add(
    object dataSource,
    CellRange range
)
vb
Function Add(
    dataSource As Object,
    range As CellRange
) As Table

Parameters

NameTypeDescription
dataSourceObject

A data source object whose data should be retrieved in the worksheet.

| | range | CellRange |

A CellRange used to create a table.

|

Returns

TypeDescription
Table

A Table object that is the newly created table.

|

Remarks

The following rules are used, depending on the dimensions of the specified range:

RangeResult
A single cell.A table is created to include all the data of the data source. It has the number of columns equal to the number of data fields, and the number of rows equal to the number of data rows in the data source. The top left corner of the table is the specified cell.
A range with a number of columns less than the number of data fields in the data source.An WorksheetDataBindingCollection.Error event occurs that indicates a column number mismatch. The table is not created.
A range with the number of columns equal to the number of data fields in the data source.A table is created with the number of rows equal to the number of data rows in the data source.
A range with a number of columns greater than the number of data fields in the data sourceA table is created that includes all columns from the data source and a number of empty columns to fill the entire range. The table has a number of rows equal to the number of data rows in the data source.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Add(Object, CellRange) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

spreadsheet-document-api-use-worksheet-data-bindings-to-process-data/CS/PerformanceCounterCorrelationExample/WorksheetProcessor.cs#L13

csharp
Worksheet sheet = wb.Worksheets[0];
Table sheetDataTable = sheet.Tables.Add(dataSource, sheet.Range["B2:C50"]);
sheet.Cells["E2"].Formula = "IFERROR(CORREL(Table1[Column1], Table1[Column2]),0)";

spreadsheet-document-api-use-worksheet-data-bindings-to-process-data/VB/PerformanceCounterCorrelationExample/WorksheetProcessor.vb#L14

vb
Dim sheet As Worksheet = wb.Worksheets(0)
Dim sheetDataTable As Table = sheet.Tables.Add(dataSource, sheet.Range("B2:C50"))
sheet.Cells("E2").Formula = "IFERROR(CORREL(Table1[Column1], Table1[Column2]),0)"

See Also

Data Binding in WinForms Spreadsheet Control

Table

WorksheetTableDataBinding

DataBindings

Error

BindTableToDataSource

TableCollection Interface

TableCollection Members

DevExpress.Spreadsheet Namespace