Xceed Workbooks for .NET v3.0 Documentation
Xceed.Workbooks.NET Assembly / Xceed.Workbooks.NET Namespace / WorksheetCollection Class
Members Example


In This Topic
    WorksheetCollection Class
    In This Topic
    Represents a collection of Worksheets in the Workbook.  
    Object Model
    WorksheetCollection ClassWorksheet Class
    Syntax
    'Declaration
     
    
    <DefaultMemberAttribute("Item")>
    Public Class WorksheetCollection 
       Inherits WorkbookElement
    'Usage
     
    
    Dim instance As WorksheetCollection
    [DefaultMember("Item")]
    public class WorksheetCollection : WorkbookElement 
    Example
    using( var doc = Workbook.Load( "test.xlsx") )   // Loads an existing Workbook named “test.xlsx”.
      {
        var worksheetA = doc.Worksheets[ 1 ];         // Gets the second worksheet. 
        var worksheetB = doc.Worksheets[ “Sheet3” ];         // Gets the worksheet named “Sheet3”. 
        doc.Worksheets.Add();                                   // Adds a new Worksheet.
        doc.Worksheets.Add( "ThirdSheet" );         // Adds a new Worksheet with a specific name.
        if( doc.Worksheets.Contains( "ThirdSheet" ) ) // Looks for a specific Worksheet.
          {
            Debug.WriteLine( "Found" );
          }
        doc.Save(); 
      }
    Inheritance Hierarchy

    System.Object
       Xceed.Workbooks.NET.WorkbookElement
          Xceed.Workbooks.NET.WorksheetCollection

    Public Properties
     NameDescription
    Public PropertyGets the number of Worksheet in the WorksheetCollection. The default is one Worksheet per Workbook.  
    Public PropertyOverloaded. 

    Gets the Worksheet element that is located at the specified Id.

    The first worksheet starts at 0.

     
    Top
    Public Methods
     NameDescription
    Public MethodOverloaded. This method allows to add a Worksheet to the WorksheetCollection.  
    Public MethodReturns true if the WorksheetCollection contains a Worksheet with the name “worksheetName”; returns false otherwise.  
    Public MethodOverloaded. This method is used to create a copy of a specific worksheet. The worksheet to be copied can be specified by its index, name or by using the Worksheet object itself.  
    Public Method  
    Public MethodOverloaded. Adds a new Worksheet at the designated location.  
    Public MethodOverloaded. Moves a Worksheet or a WorksheetRange to a selected location in the WorksheetCollection.  
    Public MethodOverloaded. Removes the Worksheet from the WorksheetCollection and offsets the index of the other Worksheets toward the deleted element.  
    Public MethodRemoves a Worksheet from the WorksheetCollection by using an index to locate it in the collection.  
    Top
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also