1

私は 3 つのデータ テーブルを持つ Ado.Net データセットを持っています。データセット名 customer とテーブルは accounts, purchases と 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

OfficeWriter の ExcelTemplate オブジェクトの BindData メソッドには、多数のオーバーロードがあります。DataSet を受け入れるものは、DataSet 内のすべての DataTable を自動的にインポートするのではなく、最初のデータのみをインポートします。DataSet 内のすべての DataTable を使用する場合は、DataTable を受け取るオーバーロードを使用する必要があります (ドキュメントを参照してください)。例えば:

//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());

次のように、ループで何かを行うこともできます。

foreach (DataTable table in myDataSet.Tables)
   {
     xlt.BindData(table, table.TableName, xlt.CreateDataBindingProperties());
   }
于 2013-05-14T21:02:11.890 に答える