// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); #region カスタムクラスの定義 //public class SalesData //{ // public List<SalesRecord> Sales; //} //public class SalesRecord //{ // public string Area; // public string City; // public string Category; // public string Name; // public double Revenue; //} #endregion #region データの初期化 var datasource = new SalesData { Sales = new List<SalesRecord>() }; var record1 = new SalesRecord { Area = "北米", City = "シカゴ", Category = "家電製品", Name = "Bose 785593-0050", Revenue = 92800 }; datasource.Sales.Add(record1); var record2 = new SalesRecord { Area = "北米", City = "ニューヨーク", Category = "家電製品", Name = "Bose 785593-0050", Revenue = 92800 }; datasource.Sales.Add(record2); var record3 = new SalesRecord { Area = "南米", City = "サンティアゴ", Category = "家電製品", Name = "Bose 785593-0050", Revenue = 19550 }; datasource.Sales.Add(record3); #endregion IWorksheet worksheet = workbook.Worksheets[0]; // テーブルを追加 ITable table = worksheet.Tables.Add(worksheet.Range["B2:F4"], true); // テーブルを追加 ITable table1 = worksheet.Tables.Add(worksheet.Range["E6:H10"], true); // テーブル列にデータフィールドを設定 table.Columns[0].DataField = "Area"; table.Columns[1].DataField = "City"; table.Columns[2].DataField = "Category"; table.Columns[3].DataField = "Name"; table.Columns[4].DataField = "Revenue"; // ExpandBoundRows に true を設定 table.ExpandBoundRows = true; // テーブルにバインディングパスを設定 table.BindingPath = "Sales"; // カスタムオブジェクトをデータソースとして設定 worksheet.DataSource = datasource; // xlsx ファイルに保存 workbook.Save("ExpandBoundRows.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook #Region "カスタムクラスの定義" 'Public Class SalesData ' Public Sales As List(Of SalesRecord) 'End Class 'Public Class SalesRecord ' Public Area As String ' Public City As String ' Public Category As String ' Public Name As String ' Public Revenue As Integer 'End Class #End Region #Region "データの初期化" Dim datasource = New SalesData With {.Sales = New List(Of SalesRecord)()} Dim record1 = New SalesRecord With { .Area = "北米", .City = "シカゴ", .Category = "家電製品", .Name = "Bose 785593-0050", .Revenue = 92800 } datasource.Sales.Add(record1) Dim record2 = New SalesRecord With { .Area = "北米", .City = "ニューヨーク", .Category = "家電製品", .Name = "Bose 785593-0050", .Revenue = 92800 } datasource.Sales.Add(record2) Dim record3 = New SalesRecord With { .Area = "南米", .City = "サンティアゴ", .Category = "家電製品", .Name = "Bose 785593-0050", .Revenue = 19550 } datasource.Sales.Add(record3) #End Region Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.DataSource = datasource ' テーブルを追加 Dim table As ITable = worksheet.Tables.Add(worksheet.Range("B2:F4"), True) ' テーブルを追加 Dim table1 As ITable = worksheet.Tables.Add(worksheet.Range("E6:H10"), True) ' テーブル列にデータフィールドを設定 table.Columns(0).DataField = "Area" table.Columns(1).DataField = "City" table.Columns(2).DataField = "Category" table.Columns(3).DataField = "Name" table.Columns(3).DataField = "Revenue" ' ExpandBoundRows に true を設定 table.ExpandBoundRows = True ' テーブルにバインディングパスを設定 table.BindingPath = "Sales" ' カスタムオブジェクトをデータソースとして設定 worksheet.DataSource = datasource ' xlsx ファイルに保存 workbook.Save("ExpandBoundRows.xlsx")