Back to Devexpress

Worksheet.Name Property

officefileapi-devexpress-dot-spreadsheet-dot-worksheet-1d2119fb.md

latest8.0 KB
Original Source

Worksheet.Name Property

Gets or sets the name of the worksheet .

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
string Name { get; set; }
vb
Property Name As String

Property Value

TypeDescription
String

A String value which specifies the worksheet name.

|

Remarks

When naming a worksheet, take into account the following constraints.

  • A worksheet name must not be equal to a name that is already contained in the collection of existing worksheets (IWorkbook.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 (‘).
  • A worksheet name must not be an empty string.

To add a new worksheet under the specified name to the workbook, use the WorksheetCollection.Add or WorksheetCollection.Insert method with the worksheet name passed as a parameter.

Example

This example demonstrates how to rename a worksheet. To do this, use the Worksheet.Name property of the corresponding Worksheet object.

View Example

csharp
// Change the name of the second worksheet.
workbook.Worksheets[1].Name = "Renamed Sheet";
vb
' Change the name of the second worksheet.
workbook.Worksheets(1).Name = "Renamed Sheet"

The following code snippets (auto-collected from DevExpress Examples) contain references to the Name property.

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.

winforms-spreadsheet-use-custom-cell-editors/CS/DevAVInvoicing/Form1.cs#L116

csharp
Worksheet sheet = spreadsheetControl1.ActiveWorksheet;
if (sheet.Name == "Invoice") {
    DefinedName invoiceItems = sheet.DefinedNames.GetDefinedName("InvoiceItems");

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/WorksheetActions.cs#L37

csharp
// Add a new worksheet under the specified name.
workbook.Worksheets.Add().Name = "TestSheet1";

wpf-spreadsheetcontrol-api-part-1/CS/SpreadsheetControl_WPF_API/SpreadsheetActions/WorksheetActions.cs#L46

csharp
// Add a new worksheet under the specified name.
workbook.Worksheets.Add().Name = "TestSheet1";

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/WorksheetActions.cs#L39

csharp
// Add a new worksheet under the specified name.
workbook.Worksheets.Add().Name = "TestSheet1";

winforms-spreadsheet-implement-microsoft-excel-format-painter/CS/WindowsFormsApplication1/FormatPainterProvider.cs#L34

csharp
{
    if (sourceCell != null && e.SheetName == sourceCell.Worksheet.Name)
        biFormatPainter.Checked = false;

winforms-spreadsheet-use-custom-cell-editors/VB/DevAVInvoicing/Form1.vb#L107

vb
Dim sheet As Worksheet = spreadsheetControl1.ActiveWorksheet
If Equals(sheet.Name, "Invoice") Then
    Dim invoiceItems As DefinedName = sheet.DefinedNames.GetDefinedName("InvoiceItems")

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/WorksheetActions.vb#L41

vb
' Add a new worksheet under the specified name.
workbook.Worksheets.Add().Name = "TestSheet1"

wpf-spreadsheetcontrol-api-part-1/VB/SpreadsheetControl_WPF_API/SpreadsheetActions/WorksheetActions.vb#L45

vb
' Add a new worksheet under the specified name.
workbook.Worksheets.Add().Name = "TestSheet1"

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/WorksheetActions.vb#L49

vb
' Add a new worksheet under the specified name.
workbook.Worksheets.Add().Name = "TestSheet1"
workbook.Worksheets.Add("TestSheet2")

winforms-spreadsheet-implement-microsoft-excel-format-painter/VB/WindowsFormsApplication1/FormatPainterProvider.vb#L38

vb
Private Sub Spreadsheet_SheetRemoving(ByVal sender As Object, ByVal e As SheetRemovingEventArgs)
    If sourceCell IsNot Nothing AndAlso Equals(e.SheetName, sourceCell.Worksheet.Name) Then biFormatPainter.Checked = False
End Sub

See Also

How to: Access a Worksheet

How to: Rename a Worksheet

How to: Move a Worksheet to another Location

Worksheets in Spreadsheet Documents

Worksheet Interface

Worksheet Members

DevExpress.Spreadsheet Namespace