[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.ITableDataSource

ITableDataSource Interface

Represents a custom table data source.

Classes that implement this interface can be used as a DataTable-like data source for template processing. An ITableDataSource exposes tabular data through row and column indexes, together with column metadata, so that it can be added to a workbook by using AddDataSource(string, object).

Namespace: GrapeCity.Documents.Excel
Assembly: DS.Documents.Excel.dll
Syntax
public interface ITableDataSource
Public Interface ITableDataSource
Examples
private sealed class ExampleTableDataSource : ITableDataSource
{
    private readonly object[,] _data =
    {
        { "Alice" },
        { "Bob" }
    };

    private readonly string[] _columns = { "Customer" };

    public object GetValue(int row, int column)
    {
        return _data[row, column];
    }

    public int GetRowCount()
    {
        return _data.GetLength(0);
    }

    public int GetColumnCount()
    {
        return _data.GetLength(1);
    }

    public string GetColumnName(int column)
    {
        return _columns[column];
    }

    public int GetColumnIndex(string columnName)
    {
        return Array.IndexOf(_columns, columnName);
    }
}

ITableDataSource dataSource = new ExampleTableDataSource();
workbook.AddDataSource("customers", dataSource);

Methods

Name Description
GetColumnCount()

Get the column count.

GetColumnIndex(string)

Get the column index.

GetColumnName(int)

Get the column name.

GetRowCount()

Get the row count.

GetValue(int, int)

Get value from the data source.