GemBox.Spreadsheet
  • Overview
  • Examples
  • Free version
  • Support
  • Pricelist

    Show / Hide Table of Contents

    ExcelWorksheetCollection Class

    Namespace:
    GemBox.Spreadsheet
    Assembly:
    GemBox.Spreadsheet.dll

    Collection of worksheets (ExcelWorksheet).

    • C#
    • VB.NET
    public sealed class ExcelWorksheetCollection : IEnumerable<ExcelWorksheet>, IEnumerable
    Public NotInheritable Class ExcelWorksheetCollection
        Implements IEnumerable(Of ExcelWorksheet), IEnumerable
    Inheritance:
    System.Object
    ExcelWorksheetCollection
    Implements
    System.Collections.Generic.IEnumerable<ExcelWorksheet>
    System.Collections.IEnumerable

    Properties

    ActiveWorksheet

    Gets or sets active worksheet.

    • C#
    • VB.NET
    public ExcelWorksheet ActiveWorksheet { get; set; }
    Public Property ActiveWorksheet As ExcelWorksheet
    Property Value
    ExcelWorksheet
    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.

    • C#
    • VB.NET
    public int Count { get; }
    Public ReadOnly Property Count As Integer
    Property Value
    System.Int32

    Item[Int32]

    Gets the worksheet with the specified index.

    • C#
    • VB.NET
    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
    ExcelWorksheet

    Item[String]

    Gets the worksheet with the specified name.

    • C#
    • VB.NET
    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
    ExcelWorksheet

    Methods

    Add(SheetType, String)

    Adds an empty worksheet to the end of the collection.

    • C#
    • VB.NET
    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
    ExcelWorksheet

    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.

    • C#
    • VB.NET
    public ExcelWorksheet Add(string worksheetName)
    Public Function Add(worksheetName As String) As ExcelWorksheet
    Parameters
    worksheetName
    System.String

    Worksheet name.

    Returns
    ExcelWorksheet

    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.

    • C#
    • VB.NET
    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
    ExcelWorksheet

    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.

    • C#
    • VB.NET
    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.

    • C#
    • VB.NET
    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.

    • C#
    • VB.NET
    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.

    • C#
    • VB.NET
    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
    ExcelWorksheet

    Newly created worksheet.

    InsertEmpty(Int32, SheetType, String)

    Inserts empty worksheet at the specified index.

    • C#
    • VB.NET
    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
    ExcelWorksheet

    Newly created worksheet.

    InsertEmpty(Int32, String)

    Inserts empty worksheet at the specified index.

    • C#
    • VB.NET
    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
    ExcelWorksheet

    Newly created worksheet.

    Move(Int32, Int32)

    Moves the worksheet at the specified index to a new location in the collection.

    • C#
    • VB.NET
    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.

    • C#
    • VB.NET
    public void Remove(int worksheetIndex)
    Public Sub Remove(worksheetIndex As Integer)
    Parameters
    worksheetIndex
    System.Int32

    The zero-based index of the worksheet.

    Remove(String)

    Removes the worksheet with the specified name.

    • C#
    • VB.NET
    public void Remove(string worksheetName)
    Public Sub Remove(worksheetName As String)
    Parameters
    worksheetName
    System.String

    Worksheet name.

    Implements

    System.Collections.Generic.IEnumerable<T>
    System.Collections.IEnumerable

    See Also

    ExcelWorksheet
    Back to top

    Facebook • Twitter • LinkedIn

    © GemBox Ltd. — All rights reserved.