//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); #region Define custom classes //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 Init data var datasource = new SalesData { Sales = new List<SalesRecord>() }; var record1 = new SalesRecord { Area = "North America", City = "Chicago", Category = "Consumer Electronics", Name = "Bose 785593-0050", Revenue = 92800 }; datasource.Sales.Add(record1); var record2 = new SalesRecord { Area = "North America", City = "New York", Category = "Consumer Electronics", Name = "Bose 785593-0050", Revenue = 92800 }; datasource.Sales.Add(record2); var record3 = new SalesRecord { Area = "South America", City = "Santiago", Category = "Consumer Electronics", Name = "Bose 785593-0050", Revenue = 19550 }; datasource.Sales.Add(record3); #endregion IWorksheet worksheet = workbook.Worksheets[0]; // Add a table. ITable table = worksheet.Tables.Add(worksheet.Range["B2:F4"], true); // Add a table. ITable table1 = worksheet.Tables.Add(worksheet.Range["E6:H10"], true); // Set table column data field. 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"; // Set ExpandBoundRows to true. table.ExpandBoundRows = true; // Binding data to table. table.BindingPath = "Sales"; // Set data source. worksheet.DataSource = datasource; // Save to an excel file workbook.Save("ExpandBoundRows.xlsx");
' Create a new Workbook Dim workbook As New Workbook #Region "Define custom classes" '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 "Init data" Dim datasource = New SalesData With {.Sales = New List(Of SalesRecord)()} Dim record1 = New SalesRecord With { .Area = "North America", .City = "Chicago", .Category = "Consumer Electronics", .Name = "Bose 785593-0050", .Revenue = 92800 } datasource.Sales.Add(record1) Dim record2 = New SalesRecord With { .Area = "North America", .City = "New York", .Category = "Consumer Electronics", .Name = "Bose 785593-0050", .Revenue = 92800 } datasource.Sales.Add(record2) Dim record3 = New SalesRecord With { .Area = "South America", .City = "Santiago", .Category = "Consumer Electronics", .Name = "Bose 785593-0050", .Revenue = 19550 } datasource.Sales.Add(record3) #End Region Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.DataSource = datasource ' Add a table. Dim table As ITable = worksheet.Tables.Add(worksheet.Range("B2:F4"), True) ' Add a table. Dim table1 As ITable = worksheet.Tables.Add(worksheet.Range("E6:H10"), True) ' Set table column data field. 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" ' Set ExpandBoundRows to true. table.ExpandBoundRows = True ' Set data source. worksheet.DataSource = datasource ' Binding data to table. table.BindingPath = "Sales" ' save to an excel file workbook.Save("ExpandBoundRows.xlsx")