Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
Description

Excerpt

Sets a DataTable as a data source to bind to a row in the template. This method will import only the first row of the DataTable.  You must insert a datamarker into the template for each column of data you want shown.

Signature
C#C#
Wiki Markup
{description}
{excerpt}Sets a DataTable as a data source to bind to a row in the template. This method will import only the first row of the DataTable.  You must insert a datamarker into the template for each column of data you want shown.
{excerpt}
{signature:C#}
 public void BindRowData(System.Data.DataTable dataSource, System.String dataSourceName, DataBindingProperties property)
Signature
{signature}
{signature:vb.net
vb.net
}
Public Sub BindRowData(ByVal dataSource As System.Data.DataTable, ByVal dataSourceName As String, ByVal [property] As DataBindingProperties)
Parameters
Param
sourcesource

The DataTable to use as the data source.

Param
dataSourceNamedataSourceNameThe name of the data marker at which to insert the values imported from the data source. For example, to bind a data source to the data marker %%
{signature}
{parameters}
{param:source}The DataTable to use as the data source.
{param}
{param:dataSourceName}The name of the data marker at which to insert the values imported from the data source. For example, to bind a data source to the data marker \%\%=Orders.OrderId, the value of dataSourceName should be "Orders". The string passed must begin with a letter.
Param
propertyproperty

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

...

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

...

Remarks

Only the first row of the DataTable 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.


{param}
{param:property}The [DataBindingProperties|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.MaxRows], [DataBindingProperties.Transpose|DataBindingProperties.Transpose], and/or [DataBindingProperties.WorksheetName|DataBindingProperties.WorksheetName] properties for the workbook.
{param}
{exceptions}
{exception:ArgumentNullException}{{BindRowData}} will throw this exception if {{null}} \(C\#\) or {{Nothing}} \(VB.NET\) is passed to the method.
{exception}
{exception:ArgumentException}{exception}
{remarks}
Only the first row of the DataTable 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|ExcelTemplate.BindCellData(Object, String, DataBindingProperties)], [BindColumnData|ExcelTemplate.BindColumnData], [BindRowData|ExcelTemplate.BindRowData], and [BindData|ExcelTemplate.BindData].

{remarks}
{example}{code:csharp|title=C#}

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

          //--- Bind the DataTable to the
          //--- %%=Orders.[Field] data marker.
          xlt.BindRowData(OrdersDT,
               "Orders",
               xlt.CreateDataBindingProperties());
          xlt.Process();
          xlt.Save(Page.Response, "EmployeeOrders.xls", false);
        
{code}
{code:vb.net
|title=vb.net
}

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

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

{example}
Example
Code Block
csharpcsharp
titleC#
Code Block
vb.nettitle