Reputation: 11
I have a Ado.Net dataset that have three datatables let say Dataset name customer and tables are accounts, purchases and profile . i do like to export them using softartisans ExcelWriter to worksheets using templates
Example
DataSet myDataSet = new DataSet();
myDataSet.Tables.Add("Customer");
myDataSet.Tables.Add("Accounts");
myDataSet.Tables.Add("Purchases");
xlt.BindData(myDataSet,null , xlt.CreateDataBindingProperties());
I do like to export theses tables into seperate excel worksheets.
Upvotes: 1
Views: 445
Reputation: 381
The BindData method of OfficeWriter's ExcelTemplate object has a number of overloads. The one that accepts a DataSet does not automatically import every DataTable in the DataSet, it only imports the first one. If you want to use every DataTable in the DataSet, you should use the overload that takes a DataTable (see the documentation). For example:
//The 2nd parameter is the dataSource name that must correspond with the first
//part of the datamarker in your template workbook (i.e. %%=Customer.FirstName)
xlt.BindData(DS.Tables["Customer"], "Customer", xlt.CreateDataBindingProperties());
You could also do something in a loop, like this:
foreach (DataTable table in myDataSet.Tables)
{
xlt.BindData(table, table.TableName, xlt.CreateDataBindingProperties());
}
Upvotes: 2