How to: Create a Table
The example below demonstrates how to format a range of cells as a table.
To create a table, add a new Table object to the worksheet’s collection of tables (Worksheet.Tables) by using the TableCollection.Add method. Pass the following parameters.
- The range of cells that you wish to format as a table.
- A Boolean value indicating whether or not the top row of the specified range should be used as the table header.
- Format the table by applying one of the built-in table styles. To do this, set the Table.Style property to the table style object from the Workbook.TableStyles collection. Access the desired style by its BuiltInTableStyleId identifier.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/spreadsheet-document-server-api-part-2-t217615
Worksheet worksheet = workbook.Worksheets[0];
// Insert a table in the worksheet.
Table table = worksheet.Tables.Add(worksheet["A1:F12"], false);
// Format the table by applying a built-in table style.
table.Style = workbook.TableStyles[BuiltInTableStyleId.TableStyleMedium20];
See Also