1

我有一个 Ado.Net 数据集,其中包含三个数据表,假设数据集名称 customer 和表是 accounts, purchase 和 profile 。我喜欢使用softartisans ExcelWriter将它们导出到使用模板的工作表

例子

 DataSet myDataSet = new DataSet();
        myDataSet.Tables.Add("Customer");
        myDataSet.Tables.Add("Accounts");
        myDataSet.Tables.Add("Purchases");
        xlt.BindData(myDataSet,null , xlt.CreateDataBindingProperties());

我确实喜欢将这些表格导出到单独的 Excel 工作表中。

4

1 回答 1

2

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());
   }
于 2013-05-14T21:02:11.890 回答