WorksheetCollection.Insert(Int32, String) Method
Creates a new worksheet under the specified name and appends it to the collection at the specified position.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v24.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
index | Int32 | A zero-based integer which specifies the position at which the new worksheet should be inserted. |
name | String | A String value that specifies the worksheet name. |
Returns
Type | Description |
---|---|
Worksheet | A Worksheet object that specifies the created worksheet. |
Remarks
When specifying a worksheet name, take into account the following constraints.
- The worksheet name must not be equal to an existing name in the collection of worksheets.
- A worksheet name must not exceed 31 characters.
- A worksheet name must not contain the following symbols: , /, ?, : ,*, [ or ]
- The worksheet name must not start and end with a single quote (‘).
If the name parameter is an empty string, a new worksheet will be created under a default name like SheetN, where N is a number that is greater by 1 than the maximum number used in worksheet names of the same type. To change the worksheet name, use the Worksheet.Name property.
If the index passed as a parameter to this method is less than zero, or exceeds the number of worksheets in the collection, this method throws an exception of the ArgumentOutOfRangeException type.
To insert a new worksheet to the end of the collection, use the WorksheetCollection.Add method.
To remove a worksheet from the collection, use the WorksheetCollection.Remove or WorksheetCollection.RemoveAt method.
Example
This example demonstrates how to add a new worksheet to a workbook. To do this, use the WorksheetCollection.Add method of the WorksheetCollection collection accessed via Workbook.Worksheets.
To insert a worksheet at the specified position in the WorksheetCollection collection, call the WorksheetCollection.Insert method with the passed worksheet zero-based index.
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.
// 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);
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Insert(Int32, String) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.