ExcelWorksheetCollection Class
Collection of worksheets (ExcelWorksheet).
public sealed class ExcelWorksheetCollection : IEnumerable<ExcelWorksheet>, IEnumerable
Public NotInheritable Class ExcelWorksheetCollection
Implements IEnumerable(Of ExcelWorksheet), IEnumerable
- Inheritance:
- System.ObjectExcelWorksheetCollection
Properties
ActiveWorksheet
Gets or sets active worksheet.
public ExcelWorksheet ActiveWorksheet { get; set; }
Public Property ActiveWorksheet As ExcelWorksheet
Property Value
Remarks
Active worksheet is the one selected when file is opened with Microsoft Excel. By default active worksheet is the first one added with Add(String) or Add(SheetType, String) methods.
GemBox.Spreadsheet Free allows setting active worksheet to only one of the first 5 worksheets, otherwise active worksheet defaults to the first worksheet.
Count
Gets the number of elements contained in the ExcelWorksheetCollection.
Property Value
- System.Int32
Item[Int32]
Gets the worksheet with the specified index.
public ExcelWorksheet this[int index] { get; }
Public ReadOnly Property Item(index As Integer) As ExcelWorksheet
Parameters
index
- System.Int32
The zero-based index of the worksheet.
Property Value
Item[String]
Gets the worksheet with the specified name.
public ExcelWorksheet this[string name] { get; }
Public ReadOnly Property Item(name As String) As ExcelWorksheet
Parameters
name
- System.String
The name of the worksheet.
Property Value
Methods
Add(SheetType, String)
Adds an empty worksheet to the end of the collection.
public ExcelWorksheet Add(SheetType type, string worksheetName)
Public Function Add(type As SheetType, worksheetName As String) As ExcelWorksheet
Parameters
type
- SheetType
The sheet type.
worksheetName
- System.String
Worksheet name.
Returns
Newly created worksheet.
Remarks
If this is the first worksheet added to the collection the ActiveWorksheet is set to this worksheet.
Exceptions
- System.ArgumentException
Worksheet name is not unique.
Add(String)
Adds an empty worksheet to the end of the collection.
public ExcelWorksheet Add(string worksheetName)
Public Function Add(worksheetName As String) As ExcelWorksheet
Parameters
worksheetName
- System.String
Worksheet name.
Returns
Newly created worksheet.
Remarks
If this is the first worksheet added to the collection the ActiveWorksheet is set to this worksheet.
Exceptions
- System.ArgumentException
Worksheet name is not unique.
AddCopy(String, ExcelWorksheet)
Adds a copy of an existing worksheet to the end of the collection.
public ExcelWorksheet AddCopy(string destinationWorksheetName, ExcelWorksheet sourceWorksheet)
Public Function AddCopy(destinationWorksheetName As String, sourceWorksheet As ExcelWorksheet) As ExcelWorksheet
Parameters
destinationWorksheetName
- System.String
Name of new worksheet.
sourceWorksheet
- ExcelWorksheet
Source worksheet.
Returns
Newly created worksheet.
Remarks
If this is the first worksheet added to the collection the ActiveWorksheet is set to this worksheet.
Exceptions
- System.ArgumentException
Worksheet name is not unique.
Contains(ExcelWorksheet)
Determines whether an ExcelWorksheet element is in the ExcelWorksheetCollection.
public bool Contains(ExcelWorksheet item)
Public Function Contains(item As ExcelWorksheet) As Boolean
Parameters
item
- ExcelWorksheet
The ExcelWorksheet to locate in the ExcelWorksheetCollection.
Returns
- System.Boolean
True if ExcelWorksheet is found in the ExcelWorksheetCollection; otherwise, false.
Contains(String)
Determines whether an ExcelWorksheet element with specified name is in the ExcelWorksheetCollection.
public bool Contains(string worksheetName)
Public Function Contains(worksheetName As String) As Boolean
Parameters
worksheetName
- System.String
The name of the ExcelWorksheet to locate in the ExcelWorksheetCollection.
Returns
- System.Boolean
True if ExcelWorksheet with specified name is found in the ExcelWorksheetCollection; otherwise, false.
GetEnumerator()
Returns an enumerator for the ExcelWorksheetCollection.
public IEnumerator<ExcelWorksheet> GetEnumerator()
Public Function GetEnumerator As IEnumerator(Of ExcelWorksheet)
Returns
- System.Collections.Generic.IEnumerator<ExcelWorksheet>
An enumerator for the ExcelWorksheetCollection.
InsertCopy(Int32, String, ExcelWorksheet)
Inserts a copy of an existing worksheet at the specified index.
public ExcelWorksheet InsertCopy(int worksheetIndex, string worksheetName, ExcelWorksheet sourceWorksheet)
Public Function InsertCopy(worksheetIndex As Integer, worksheetName As String, sourceWorksheet As ExcelWorksheet) As ExcelWorksheet
Parameters
worksheetIndex
- System.Int32
The zero-based index of the worksheet.
worksheetName
- System.String
Worksheet name.
sourceWorksheet
- ExcelWorksheet
Source worksheet to copy.
Returns
Newly created worksheet.
InsertEmpty(Int32, SheetType, String)
Inserts empty worksheet at the specified index.
public ExcelWorksheet InsertEmpty(int worksheetIndex, SheetType type, string worksheetName)
Public Function InsertEmpty(worksheetIndex As Integer, type As SheetType, worksheetName As String) As ExcelWorksheet
Parameters
worksheetIndex
- System.Int32
The zero-based index of the worksheet.
type
- SheetType
The sheet type.
worksheetName
- System.String
Worksheet name.
Returns
Newly created worksheet.
InsertEmpty(Int32, String)
Inserts empty worksheet at the specified index.
public ExcelWorksheet InsertEmpty(int worksheetIndex, string worksheetName)
Public Function InsertEmpty(worksheetIndex As Integer, worksheetName As String) As ExcelWorksheet
Parameters
worksheetIndex
- System.Int32
The zero-based index of the worksheet.
worksheetName
- System.String
Worksheet name.
Returns
Newly created worksheet.
Move(Int32, Int32)
Moves the worksheet at the specified index to a new location in the collection.
public void Move(int oldIndex, int newIndex)
Public Sub Move(oldIndex As Integer, newIndex As Integer)
Parameters
oldIndex
- System.Int32
The zero-based index specifying the location of the worksheet to be moved.
newIndex
- System.Int32
The zero-based index specifying the new location of the worksheet.
Remove(Int32)
Removes the worksheet with the specified index.
Parameters
worksheetIndex
- System.Int32
The zero-based index of the worksheet.
Remove(String)
Removes the worksheet with the specified name.
Parameters
worksheetName
- System.String
Worksheet name.