Back to Devexpress

WorksheetCollection.Item[String] Property

officefileapi-devexpress-dot-spreadsheet-dot-worksheetcollection-dot-item-x28-system-dot-string-x29.md

latest4.3 KB
Original Source

WorksheetCollection.Item[String] Property

Gets a worksheet by its name.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
Worksheet this[string name] { get; }
vb
ReadOnly Property Item(name As String) As Worksheet

Parameters

NameTypeDescription
nameString

A String value that specifies the name of the worksheet to get.

|

Property Value

TypeDescription
Worksheet

A Worksheet object that is the worksheet with the specified name.

|

Remarks

Use the Item property to obtain a worksheet by its name from the workbook’s collection of worksheets. When searching, the name parameter value is compared to the Worksheet.Name property of worksheet objects. If no matches are found, an exception is thrown. To check whether a worksheet with the specified name exists in the collection, use the Contains property.

A worksheet can be also accessed by its index in the collection.

Example

This example demonstrates how to access worksheets in a workbook. Use the Workbook.Worksheets property to get a collection of worksheets contained in a workbook (the WorksheetCollection object).

To get an individual worksheet by its index or name, use the WorksheetCollection.Item property.

csharp
using DevExpress.Spreadsheet;
// ...

Workbook workbook = new Workbook();

// Access a collection of worksheets.
WorksheetCollection worksheets = workbook.Worksheets;

// Access a worksheet by its index.
Worksheet worksheet1 = workbook.Worksheets[0];

// Access a worksheet by its name.
Worksheet worksheet2 = workbook.Worksheets["Sheet2"];
vb
Imports DevExpress.Spreadsheet
' ...

Dim workbook As New Workbook()

' Access a collection of worksheets.
Dim worksheets As WorksheetCollection = workbook.Worksheets

' Access a worksheet by its index.
Dim worksheet1 As Worksheet = workbook.Worksheets(0)

' Access a worksheet by its name.
Dim worksheet2 As Worksheet = workbook.Worksheets("Sheet2")

See Also

Contains

Add

Insert

Name

How to: Access a Worksheet

How to: Set an Active Worksheet

How to: Add a New Worksheet

How to: Delete a Worksheet

How to: Rename a Worksheet

How to: Move a Worksheet to another Location

How to: Show and Hide a Worksheet

WorksheetCollection Interface

WorksheetCollection Members

DevExpress.Spreadsheet Namespace