How to: Add a New Worksheet
- 2 min to read
You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.
To specify a worksheet name, use the Worksheet.Name property or pass the worksheet name to the WorksheetCollection.Add or WorksheetCollection.Insert method as a parameter. When naming a worksheet, take into account the constraints listed in the How to: Rename a Worksheet document.
A complete sample project is available at https://github.com/DevExpress-Examples/spreadsheet-document-server-api-e4339
// Add a new worksheet to the workbook. The worksheet will be inserted into the end of the existing worksheet collection // under the name "SheetN", where N is a number following the largest number used in worksheet names in the previously existing collection. workbook.Worksheets.Add(); // Add a new worksheet under the specified name. workbook.Worksheets.Add().Name = "TestSheet1"; workbook.Worksheets.Add("TestSheet2"); // Add a new worksheet to the specified position in the collection of worksheets. workbook.Worksheets.Insert(1, "TestSheet3"); workbook.Worksheets.Insert(3);
The image below shows the result (the modified file is opened in Microsoft® Excel®).