Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Description

Excerpt

Sets a DataSet as a data source to bind to a row in the template.   This method will import only the first row of the first DataTable of the DataSet.

...

  You must insert a datamarker into the template for each column of data you want

...

shown.

Signature
C#
C#
  public void BindRowData(System.Data.DataSet dataSource, System.String dataSourceName, DataBindingProperties property)
Signature
vb.net
vb.net

Public Sub BindRowData(ByVal dataSource As System.Data.DataSet, ByVal dataSourceName As String, ByVal [property] As DataBindingProperties)

Parameters

Param
source
source

The DataSet to use as the data source.

...

Param
property
property

The DataBindingProperties object which contains information about how the data should be bound to the template. property Must be specified, but the DataBindingProperties need not be set beforehand. To bind data to a template with the default DataBindingProperties, pass in ExcelTemplate.CreateDataBindingProperties() as the property value. Otherwise, use the ExcelTemplate.CreateDataBindingProperties() method to generate a new DataBindingProperties object and set the DataBindingProperties.MaxRows, DataBindingProperties.Transpose, and/or DataBindingProperties.WorksheetName properties for the workbook.

Exceptions

Exception
ArgumentNullException
ArgumentNullException

BindRowData will throw this exception if null (C#) or Nothing (VB.NET) is passed to the method.

Exception
ArgumentException
ArgumentException
 

Remarks

Only the first row of the DataSet will be used. This method is commonly used to create a set of key-value pairs via a single row of data.

You can set several data sources for a single template. Use the following methods to set template data sources: BindCellData, BindColumnData, BindRowData, and BindData.

Example
Code Block
csharp
csharp
titleC#
          

...

ExcelTemplate xlt = new ExcelTemplate();
          xlt.Open(@"C:\ExcelWriter\EmployeeOrdersTemplate.xls");

          //--- Bind the DataSet to the
          //--- %%=Orders.[Field] data marker.
          xlt.BindRowData(OrdersDS,
               "Orders",
               xlt.CreateDataBindingProperties());
          xlt.Process();
          xlt.Save(Page.Response, "EmployeeOrders.xls", false);
        
Code Block
vb.net
vb.net
titlevb.net
          

...

Dim xlt As New ExcelTemplate()
          xlt.Open("C:\ExcelWriter\EmployeeOrdersTemplate.xls")

          '--- Bind the DataSet to the
          '--- %%=Orders.[Field] data marker.
          xlt.BindRowData(OrdersDS, _
               "Orders", _
               xlt.CreateDataBindingProperties())
          xlt.Process()
          xlt.Save(Page.Response, "EmployeeOrders.xls", False)