[]
        
(Showing Draft Content)

IWorksheets

Interface IWorksheets

All Superinterfaces:
Iterable<IWorksheet>

public interface IWorksheets extends Iterable<IWorksheet>
Represents a collection of all worksheets in a workbook.

This interface provides access to the worksheets contained in a workbook and supports retrieving, adding, copying, moving, and selecting worksheets. You can obtain an IWorksheets instance from Workbook.getWorksheets().


 IWorksheets worksheets = workbook.getWorksheets();
 IWorksheet sheet1 = worksheets.get(0);
 IWorksheet sheet2 = worksheets.add();
 
  • Method Details

    • getCount

      int getCount()
      Returns the number of IWorksheet objects in the collection.
      
       IWorksheets worksheets = workbook.getWorksheets();
       IWorksheet sheet2 = worksheets.add();
       int count = worksheets.getCount(); // count is 2
       
      Returns:
      The number of IWorksheet objects in the collection.
    • get

      IWorksheet get(int index)
      Gets the worksheet using the index.

      Use this method to retrieve a worksheet from the workbook's worksheet collection by its position.

      
       IWorksheets worksheets = workbook.getWorksheets();
       IWorksheet sheet = worksheets.get(0);
       sheet.getRange("A1").setValue("Hello");
       
      Parameters:
      index - The worksheet index.
      Returns:
      The worksheet at the specified index.
    • get

      IWorksheet get(String name)
      Gets the worksheet with the specified name.

      Use this method to retrieve a worksheet from the collection by its name.

      
       IWorksheets worksheets = workbook.getWorksheets();
       worksheet.setName("Data");
       IWorksheet dataSheet = worksheets.get("Data");
       
      Parameters:
      name - The worksheet name.
      Returns:
      The worksheet with the specified name. Returns null if no worksheet with the specified name is found.
    • get

      IWorksheets get(String[] name)
      Gets the worksheets with the specified names.

      Use this method to retrieve a filtered IWorksheets collection that contains the worksheets whose names are specified in the array.

      
       worksheet.setName("Data");
       workbook.getWorksheets().add().setName("Summary");
       IWorksheets sheets = workbook.getWorksheets().get(new String[] {"Data", "Summary"});
       sheets.select();
       
      Parameters:
      name - An array of worksheet names to retrieve. Must not be null or empty.
      Returns:
      An IWorksheets collection that contains the worksheets with the specified names.
      Throws:
      NullPointerException - if name is null.
      IllegalArgumentException - if name is empty, or if any specified worksheet name is not found in the current collection.
    • select

      void select()
      Selects the worksheets in this collection and replaces the current selection.
      
       worksheet.setName("Data");
       workbook.getWorksheets().add().setName("Summary");
       IWorksheets sheets = workbook.getWorksheets().get(new String[] {"Data", "Summary"});
       sheets.select();
       
    • select

      void select(boolean replace)
      Selects the worksheets in this collection.
      
       worksheet.setName("Data");
       workbook.getWorksheets().add().setName("Summary");
       IWorksheets sheets = workbook.getWorksheets().get(new String[] {"Data", "Summary"});
       sheets.select(false);
       
      Parameters:
      replace - true to replace the current selection; false to extend the current selection to include these worksheets.
    • add

      IWorksheet add()
      Creates a new worksheet. The new worksheet becomes the active sheet.
      
       IWorksheets worksheets = workbook.getWorksheets();
       IWorksheet newSheet = worksheets.add();
       newSheet.getRange("A1").setValue("New sheet");
       
      Returns:
      the new worksheet.
    • add

      IWorksheet add(SheetType type)
      Creates a new sheet. The new sheet becomes the active sheet.
      
       IWorksheets worksheets = workbook.getWorksheets();
       IWorksheet chartSheet = worksheets.add(SheetType.Chart);
       
      Parameters:
      type - The sheet's type.
      Returns:
      the new worksheet.
    • addAfter

      IWorksheet addAfter(IWorksheet sheet)
      Creates a new worksheet and inserts it after the specified sheet.
      
       IWorksheets worksheets = workbook.getWorksheets();
       IWorksheet firstSheet = worksheets.get(0);
       IWorksheet newSheet = worksheets.addAfter(firstSheet);
       
      Parameters:
      sheet - The insert sheet.
      Returns:
      the new worksheet.
    • addBefore

      IWorksheet addBefore(IWorksheet sheet)
      Creates a new worksheet and inserts it before the specified sheet.
      
       IWorksheets worksheets = workbook.getWorksheets();
       IWorksheet firstSheet = worksheets.get(0);
       IWorksheet newSheet = worksheets.addBefore(firstSheet);
       
      Parameters:
      sheet - The specified sheet.
      Returns:
      the new worksheet.
    • contains

      boolean contains(IWorksheet worksheet)
      Returns true if the specified Worksheet is contained by the collection of worksheets; otherwise, false is returned.
      
       IWorksheets worksheets = workbook.getWorksheets();
       IWorksheet sheet = worksheets.get(0);
       boolean contains = worksheets.contains(sheet);
       
      Parameters:
      worksheet - The IWorksheet object.
      Returns:
      Returns whether the specified worksheet is contained by the collection of worksheets.
    • copy

      IWorksheets copy()
      Copies the sheet collection to the end of the current workbook.
      
       IWorksheets worksheets = workbook.getWorksheets();
       IWorksheets copiedSheets = worksheets.copy();
       
      Returns:
      The new copied sheet collection.
    • copy

      IWorksheets copy(IWorkbook targetWorkbook)
      Copies the sheet collection to the end of the specified workbook.
      
       IWorksheets worksheets = workbook.getWorksheets();
       Workbook targetWorkbook = new Workbook();
       IWorksheets copiedSheets = worksheets.copy(targetWorkbook);
       
      Parameters:
      targetWorkbook - Specifies the workbook to which the sheet collection will be copied.
      Returns:
      The new copied sheet collection.
    • copyAfter

      IWorksheets copyAfter(IWorksheet targetWorksheet)
      Copies the sheet collection to the location after the specified sheet.
      
       IWorksheets worksheets = workbook.getWorksheets();
       IWorksheet targetSheet = workbook.getWorksheets().add();
       IWorksheets copiedSheets = worksheets.copyAfter(targetSheet);
       
      Parameters:
      targetWorksheet - The sheet after which the copied sheet collection will be placed. It can be the sheet of the same or another workbook.
      Returns:
      The new copied sheet collection.
    • copyBefore

      IWorksheets copyBefore(IWorksheet targetWorksheet)
      Copies the sheet collection to the location before the specified sheet.
      
       IWorksheets worksheets = workbook.getWorksheets();
       IWorksheet targetSheet = workbook.getWorksheets().add();
       IWorksheets copiedSheets = worksheets.copyBefore(targetSheet);
       
      Parameters:
      targetWorksheet - The sheet before which the copied sheet collection will be placed. It can be the sheet of the same or another workbook.
      Returns:
      The new copied sheet collection.
    • move

      IWorksheets move()
      Moves the sheet collection to the end of the current workbook.
      
       workbook.getWorksheets().add().setName("Summary");
       IWorksheets sheets = workbook.getWorksheets().get(new String[] {"Sheet1", "Summary"});
       IWorksheets movedSheets = sheets.move();
       
      Returns:
      The moved sheet collection.
    • move

      IWorksheets move(IWorkbook targetWorkbook)
      Moves the sheet collection to the end of the specified workbook.
      
       workbook.getWorksheets().add().setName("Summary");
       IWorksheets sheets = workbook.getWorksheets().get(new String[] {"Sheet1", "Summary"});
       Workbook targetWorkbook = new Workbook();
       IWorksheets movedSheets = sheets.move(targetWorkbook);
       
      Parameters:
      targetWorkbook - Specifies the workbook to which the sheet collection will be moved.
      Returns:
      The moved sheet collection.
    • moveAfter

      IWorksheets moveAfter(IWorksheet targetWorksheet)
      Moves the sheet collection to the location after the specified sheet.
      
       workbook.getWorksheets().add().setName("Summary");
       IWorksheets sheets = workbook.getWorksheets().get(new String[] {"Sheet1", "Summary"});
       IWorksheet targetSheet = workbook.getWorksheets().add();
       IWorksheets movedSheets = sheets.moveAfter(targetSheet);
       
      Parameters:
      targetWorksheet - The sheet after which the moved sheet collection will be placed. It can be the sheet of the same or another workbook.
      Returns:
      The moved sheet collection.
    • moveBefore

      IWorksheets moveBefore(IWorksheet targetWorksheet)
      Moves the sheet collection to the location before the specified sheet.
      
       workbook.getWorksheets().add().setName("Summary");
       IWorksheets sheets = workbook.getWorksheets().get(new String[] {"Sheet1", "Summary"});
       IWorksheet targetSheet = workbook.getWorksheets().add();
       IWorksheets movedSheets = sheets.moveBefore(targetSheet);
       
      Parameters:
      targetWorksheet - The sheet before which the moved sheet collection will be placed. It can be the sheet of the same or another workbook.
      Returns:
      The moved sheet collection.
    • indexOf

      int indexOf(IWorksheet worksheet)
      Returns the zero-based index of the specified worksheet in the collection.
      
       IWorksheets worksheets = workbook.getWorksheets();
       IWorksheet sheet = worksheets.get(0);
       int index = worksheets.indexOf(sheet);
       
      Parameters:
      worksheet - The IWorksheet object.
      Returns:
      Returns the zero-based index of the specified worksheet in the collection.