[]
        
(Showing Draft Content)

IWorksheet

Interface IWorksheet


public interface IWorksheet
Represents a worksheet in a workbook. IWorksheet provides access to worksheet content, ranges, views, events, and protection features, which can be used to read and modify cell data, manage worksheet state, and perform worksheet-related operations. This interface is typically obtained through Workbook.getActiveSheet() or Workbook.getWorksheets().

 IWorksheet sheet = workbook.getActiveSheet();
 IRange range = sheet.getRange("A1:B2");
 range.setValue(new Object[][] {
     {"Name", "Value"},
     {"Test", 100}
 });
 
  • Method Details

    • getActivatedEvent

      Event<EventHandler<EventArgs>> getActivatedEvent()
      Occurs when the worksheet is activated.
      
       IWorksheet detailSheet = workbook.getWorksheets().add();
       final String[] activatedSheetName = {null};
       detailSheet.getActivatedEvent().addListener(new EventHandler<EventArgs>() {
           public void invoke(Object sender, EventArgs e) {
               activatedSheetName[0] = ((IWorksheet)sender).getName();
           }
       });
       detailSheet.activate();
       
      Returns:
      The event that occurs when the worksheet is activated.
    • getBeforeDeleteEvent

      Event<EventHandler<EventArgs>> getBeforeDeleteEvent()
      Occurs before the worksheet is deleted.
      
       IWorksheet detailSheet = workbook.getWorksheets().add();
       final String[] deletedSheetName = {null};
       detailSheet.getBeforeDeleteEvent().addListener(new EventHandler<EventArgs>() {
           public void invoke(Object sender, EventArgs e) {
               deletedSheetName[0] = ((IWorksheet)sender).getName();
           }
       });
       detailSheet.delete();
       
      Returns:
      The event that occurs before the worksheet is deleted.
    • getChangedEvent

      Event<EventHandler<RangeEventArgs>> getChangedEvent()
      Occurs when something changes in the cells.
      
       final String[] changedAddress = {null};
       worksheet.getChangedEvent().addListener(new EventHandler<RangeEventArgs>() {
           public void invoke(Object sender, RangeEventArgs e) {
               changedAddress[0] = e.getRange().getAddress();
           }
       });
       worksheet.getRange("B2").setValue("Updated");
       
      Returns:
      The event that occurs when something changes in the cells.
    • getDeactivatedEvent

      Event<EventHandler<EventArgs>> getDeactivatedEvent()
      Occurs when the worksheet is deactivated.
      
       IWorksheet detailSheet = workbook.getWorksheets().add();
       final String[] deactivatedSheetName = {null};
       worksheet.getDeactivatedEvent().addListener(new EventHandler<EventArgs>() {
           public void invoke(Object sender, EventArgs e) {
               deactivatedSheetName[0] = ((IWorksheet)sender).getName();
           }
       });
       detailSheet.activate();
       
      Returns:
      The event that occurs when the worksheet is deactivated.
    • getSelectionChangeEvent

      Event<EventHandler<RangeEventArgs>> getSelectionChangeEvent()
      Occurs when the selection changes on a worksheet.
      
       final String[] selectionAddress = {null};
       worksheet.getSelectionChangeEvent().addListener(new EventHandler<RangeEventArgs>() {
           public void invoke(Object sender, RangeEventArgs e) {
               selectionAddress[0] = e.getRange().getAddress();
           }
       });
       worksheet.getRange("C3:D4").select();
       
      Returns:
      The event that occurs when the selection changes on a worksheet.
    • getControls

      IControlCollection getControls()
      Gets the form control collection of this worksheet.

      The returned IControlCollection provides access to the form controls contained in the worksheet, such as buttons, check boxes, and drop-down lists.

      
       worksheet.getControls().addButton(20, 20, 100, 24);
       IControlCollection controls = worksheet.getControls();
       IControl control = controls.get(0);
       
      Returns:
      The form control collection of this worksheet.
    • getSheetView

      IWorksheetView getSheetView()
      Gets the view settings of this worksheet.

      Use the returned IWorksheetView object to access worksheet display settings such as gridline visibility, reading direction, scroll position, zoom, and view type.

      
       worksheet.getRange("A1").setValue("Name");
       IWorksheetView sheetView = worksheet.getSheetView();
       sheetView.setDisplayGridlines(false);
       sheetView.setZoom(150);
       
      Returns:
      The IWorksheetView object that represents the view settings of this worksheet.
    • getVisible

      Visibility getVisible()
      Gets the visibility state of the worksheet.

      The returned value indicates whether the worksheet is currently shown, hidden, or very hidden.

      
       IWorksheet detailSheet = workbook.getWorksheets().add();
       detailSheet.setName("Detail");
       detailSheet.setVisible(Visibility.Hidden);
       Visibility visibility = detailSheet.getVisible();
       
      Returns:
      The visibility state of the worksheet, such as Visibility.Visible, Visibility.Hidden, or Visibility.VeryHidden.
    • setVisible

      void setVisible(Visibility value)
      Sets the visibility state of the worksheet.

      Use this method to display the worksheet, hide it so that users can show it again, or make it very hidden so that it cannot be shown directly through the user interface.

      
       IWorksheet detailSheet = workbook.getWorksheets().add();
       detailSheet.setName("Detail");
       detailSheet.setVisible(Visibility.Hidden);
       Visibility currentVisibility = detailSheet.getVisible();
       
      Parameters:
      value - The worksheet visibility state, such as Visibility.Visible, Visibility.Hidden, or Visibility.VeryHidden.
    • getActiveCell

      IRange getActiveCell()
      Gets the active cell.

      The active cell is returned as a single-cell IRange. Returns null if the worksheet does not have a current selection.

      
       worksheet.getRange("C3").activate();
       IRange cell = worksheet.getActiveCell();
       cell.setValue("Active");
       
      Returns:
      A single-cell IRange that represents the active cell, or null if the worksheet does not have a current selection.
    • getAutoFilter

      IAutoFilter getAutoFilter()
      Gets the IAutoFilter object for the worksheet.

      The returned object provides access to the filter range, filters, and sort settings for the worksheet's AutoFilter. Returns null if AutoFilter is not enabled on the worksheet.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Value"},
           {"A", 100},
           {"B", 200}
       });
       worksheet.getRange("A1:B3").autoFilter();
       IAutoFilter autoFilter = worksheet.getAutoFilter();
       IRange filterRange = autoFilter.getRange();
       
      Returns:
      The IAutoFilter object for the worksheet, or null if AutoFilter is not enabled.
    • getAutoFilterMode

      boolean getAutoFilterMode()
      Gets whether the AutoFilter drop-down arrows are currently displayed on the sheet.

      This property indicates whether the worksheet is showing the AutoFilter drop-down buttons for filtered ranges.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Value"},
           {"A", 100},
           {"B", 200}
       });
       worksheet.getRange("A1:B3").autoFilter();
       worksheet.setAutoFilterMode(true);
       boolean autoFilterMode = worksheet.getAutoFilterMode();
       
      Returns:
      true if the AutoFilter drop-down arrows are currently displayed on the sheet; otherwise, false.
    • setAutoFilterMode

      void setAutoFilterMode(boolean value)
      Sets whether the AutoFilter drop-down arrows are currently displayed on the sheet.

      This property indicates whether the worksheet is showing the AutoFilter drop-down buttons for filtered ranges.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Value"},
           {"A", 100},
           {"B", 200}
       });
       worksheet.getRange("A1:B3").autoFilter();
       worksheet.setAutoFilterMode(false);
       
      Parameters:
      value - true if the AutoFilter drop-down arrows are currently displayed on the sheet; otherwise, false.
    • getColumns

      IRange getColumns()
      Gets the IRange object that represents all the columns on the worksheet.

      The returned range can be used to access or manipulate columns by index.

      
       worksheet.getRange("A1").setValue("Name");
       worksheet.getRange("B1").setValue("Value");
       IRange columns = worksheet.getColumns();
       IRange firstColumn = columns.get(0);
       
      Returns:
      The IRange object that represents all the columns on the worksheet.
    • getCells

      IRange getCells()
      Gets the IRange object that represents all cells in the worksheet.

      The returned range covers the entire worksheet, including cells that are not currently in use.

      
       worksheet.getRange("A1").setValue("Name");
       worksheet.getRange("B2").setValue(100);
       IRange cells = worksheet.getCells();
       IRange firstCell = cells.get(0, 0);
       
      Returns:
      An IRange object that represents all cells in the worksheet.
    • getComments

      IComments getComments()
      Gets the IComments collection that represents all the comments in the worksheet.

      Use this method to access and enumerate cell comments in the current worksheet.

      
       worksheet.getRange("B2").addComment("Review this value");
       IComments comments = worksheet.getComments();
       IComment comment = comments.get(0);
       
      Returns:
      The IComments collection that represents all the comments in the worksheet.
    • getCommentsThreaded

      ICommentsThreaded getCommentsThreaded()
      Gets the ICommentsThreaded collection that represents all threaded comments in the worksheet.

      Each item in the returned collection is an ICommentThreaded object. Threaded comments are stored in the collection in row-major order.

      
       worksheet.getRange("C3").addCommentThreaded("Review this value", "Alex");
       ICommentsThreaded commentsThreaded = worksheet.getCommentsThreaded();
       ICommentThreaded comment = commentsThreaded.get(0);
       
      Returns:
      The ICommentsThreaded collection that contains all threaded comments in the worksheet.
    • getStandardWidth

      double getStandardWidth()
      Gets the standard width, in points, for columns in the worksheet.

      This value represents the worksheet's default column width setting.

      
       worksheet.getRange("A:A").setUseStandardWidth(true);
       worksheet.setStandardWidth(72.0);
       double standardWidth = worksheet.getStandardWidth();
       double firstColumnWidth = worksheet.getRange("A:A").getColumnWidth();
       
      Returns:
      The standard column width, in points.
    • getStandardWidthInPixel

      double getStandardWidthInPixel()
      Gets the standard width, in pixels, for columns in the worksheet.

      This value represents the worksheet's default column width setting in pixel units.

      
       worksheet.getRange("A:A").setUseStandardWidth(true);
       worksheet.setStandardWidthInPixel(80);
       double standardWidthInPixel = worksheet.getStandardWidthInPixel();
       double firstColumnWidthInPixel = worksheet.getRange("A:A").getColumnWidthInPixel();
       
      Returns:
      The standard column width, in pixels.
    • setStandardWidth

      void setStandardWidth(double value)
      Sets the standard width, in points, for columns in the worksheet.

      This value represents the worksheet's default column width setting.

      
       worksheet.getRange("A:A").setUseStandardWidth(true);
       worksheet.setStandardWidth(72.0);
       double firstColumnWidth = worksheet.getRange("A:A").getColumnWidth();
       
      Parameters:
      value - The standard column width, in points.
    • setStandardWidthInPixel

      void setStandardWidthInPixel(double value)
      Sets the standard width, in pixels, for columns in the worksheet.

      This value represents the worksheet's default column width setting in pixel units.

      
       worksheet.getRange("A:A").setUseStandardWidth(true);
       worksheet.setStandardWidthInPixel(80);
       double firstColumnWidthInPixel = worksheet.getRange("A:A").getColumnWidthInPixel();
       
      Parameters:
      value - The standard column width, in pixels.
    • getStandardHeight

      double getStandardHeight()
      Gets the default row height for the worksheet, in points.

      To get the corresponding pixel value, use getStandardHeightInPixel().

      
       worksheet.setStandardHeight(18.0);
       double standardHeight = worksheet.getStandardHeight();
       
      Returns:
      The default row height, in points.
    • getStandardHeightInPixel

      double getStandardHeightInPixel()
      Gets the default row height for the worksheet, in pixels.

      To get the corresponding value in points, use getStandardHeight().

      
       worksheet.setStandardHeightInPixel(24.0);
       double standardHeightInPixel = worksheet.getStandardHeightInPixel();
       
      Returns:
      The default row height, in pixels.
    • setStandardHeight

      void setStandardHeight(double value)
      Sets the default row height for the worksheet, in points.
      
       worksheet.setStandardHeight(18.0);
       
      Parameters:
      value - The default row height, in points.
    • setStandardHeightInPixel

      void setStandardHeightInPixel(double value)
      Sets the default row height for the worksheet, in pixels.
      
       worksheet.setStandardHeightInPixel(24.0);
       
      Parameters:
      value - The default row height, in pixels.
    • getFilterMode

      boolean getFilterMode()
      Gets whether the worksheet is currently in filter mode.

      Filter mode indicates that a filter has been applied and the worksheet is actively filtering data. This differs from getAutoFilterMode(), which indicates whether AutoFilter is enabled on the worksheet.

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Name", "Value"},
           {"A", 100},
           {"B", 200},
           {"C", 100}
       });
       worksheet.getRange("A1:B4").autoFilter(1, 100);
       boolean filterMode = worksheet.getFilterMode();
       
      Returns:
      true if the worksheet is actively filtering data; otherwise, false.
    • getHyperlinks

      IHyperlinks getHyperlinks()
      Gets the collection of hyperlinks in the worksheet.

      Use this method to access, add, and manage worksheet-level hyperlinks through the returned IHyperlinks collection.

      
       worksheet.getRange("A1").setValue("Example App");
       worksheet.getHyperlinks().add(worksheet.getRange("A1"), "https://www.example.com");
       IHyperlinks hyperlinks = worksheet.getHyperlinks();
       IHyperlink hyperlink = hyperlinks.get(0);
       
      Returns:
      The IHyperlinks collection that contains the hyperlinks in the worksheet.
    • getIndex

      int getIndex()
      Gets the zero-based position of the worksheet in the workbook's worksheet collection.

      The returned value reflects the current worksheet order in the collection.

      
       workbook.getWorksheets().add();
       IWorksheet secondSheet = workbook.getWorksheets().get(1);
       int index = secondSheet.getIndex();
       
      Returns:
      The zero-based position of the worksheet in the workbook's worksheet collection.
    • setIndex

      void setIndex(int value)
      Moves the worksheet to the specified zero-based position in the workbook's worksheet collection.
      
       workbook.getWorksheets().add();
       IWorksheet secondSheet = workbook.getWorksheets().get(1);
       secondSheet.setIndex(0);
       
      Parameters:
      value - The zero-based position of the worksheet in the workbook's worksheet collection.
    • getRowCount

      int getRowCount()
      Gets the row count of the worksheet.

      This value represents the current number of rows available in the worksheet.

      
       worksheet.setRowCount(20);
       int rowCount = worksheet.getRowCount();
       
      Returns:
      The row count of the worksheet.
    • setRowCount

      void setRowCount(int value)
      Sets the row count of the worksheet.

      This value represents the current number of rows available in the worksheet.

      
       worksheet.setRowCount(20);
       
      Parameters:
      value - The row count of the worksheet.
    • getColumnCount

      int getColumnCount()
      Gets the current column count of the worksheet.

      This value represents the number of columns currently defined on the worksheet. It reflects the value set through setColumnCount(int).

      
       worksheet.setColumnCount(12);
       int columnCount = worksheet.getColumnCount();
       
      Returns:
      The current number of columns in the worksheet.
    • setColumnCount

      void setColumnCount(int value)
      Sets the current column count of the worksheet.
      
       worksheet.setColumnCount(12);
       
      Parameters:
      value - The current number of columns in the worksheet.
    • getBackgroundPicture

      byte[] getBackgroundPicture()
      Gets the background image data of the worksheet.
      
       byte[] picture = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get("background.png"));
       worksheet.setBackgroundPicture(picture);
       byte[] backgroundPicture = worksheet.getBackgroundPicture();
       
      Returns:
      A byte array that contains the worksheet background image data, or an empty byte array if no background image is set.
    • setBackgroundPicture

      void setBackgroundPicture(byte[] picture)
      Sets the background image data of the worksheet.
      
       byte[] picture = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get("background.png"));
       worksheet.setBackgroundPicture(picture);
       
      Parameters:
      picture - A byte array that contains the background image data, or null to remove the background image.
    • getName

      String getName()
      Gets the name of the worksheet.

      This property returns the display name used to identify the worksheet in the workbook.

      
       worksheet.setName("Summary");
       String name = worksheet.getName();
       
      Returns:
      The name of the worksheet.
    • setName

      void setName(String value)
      Sets the name of the worksheet.

      This property Sets the display name used to identify the worksheet in the workbook.

      
       worksheet.setName("Summary");
       
      Parameters:
      value - The name of the worksheet.
    • getNames

      INames getNames()
      Returns the INames collection that represents all the worksheet-specific names (names defined with the "WorksheetName!" prefix).
      
       worksheet.getNames().add("LocalTotal", "=Sheet1!$A$1");
       INames names = worksheet.getNames();
       
      Returns:
      The INames collection that represents all worksheet-specific names (names defined with the "WorksheetName!" prefix).
    • getOutline

      IOutline getOutline()
      Gets the IOutline object that represents the outline for the worksheet.

      Use the returned outline object to access and configure worksheet outline settings for grouped rows and columns.

      
       IOutline outline = worksheet.getOutline();
       outline.showLevels(1, 0);
       
      Returns:
      The IOutline object for the worksheet.
    • getShowRowOutline

      boolean getShowRowOutline()
      Gets whether outline symbols for grouped rows are displayed.

      This setting applies to SpreadJS (SJS) serialization and viewing scenarios.

      
       worksheet.setShowRowOutline(false);
       boolean showRowOutline = worksheet.getShowRowOutline();
       
      Returns:
      true if outline symbols for grouped rows are displayed; otherwise, false.
    • setShowRowOutline

      void setShowRowOutline(boolean value)
      Sets whether outline symbols for grouped rows are displayed.

      This setting applies to SpreadJS (SJS) serialization and viewing scenarios.

      
       worksheet.setShowRowOutline(false);
       
      Parameters:
      value - true if outline symbols for grouped rows are displayed; otherwise, false.
    • getShowColumnOutline

      boolean getShowColumnOutline()
      Gets whether outline symbols for grouped columns are displayed.

      This setting applies to SpreadJS (SJS) serialization and viewing scenarios.

      
       worksheet.setShowColumnOutline(false);
       boolean showColumnOutline = worksheet.getShowColumnOutline();
       
      Returns:
      true if outline symbols for grouped columns are displayed; otherwise, false.
    • setShowColumnOutline

      void setShowColumnOutline(boolean value)
      Sets whether outline symbols for grouped columns are displayed.

      This setting applies to SpreadJS (SJS) serialization and viewing scenarios.

      
       worksheet.setShowColumnOutline(false);
       
      Parameters:
      value - true if outline symbols for grouped columns are displayed; otherwise, false.
    • getPivotTables

      IPivotTables getPivotTables()
      Gets the collection of PivotTable reports on the worksheet.

      Use this method to access existing PivotTable reports on the worksheet or to add new ones through the returned IPivotTables collection.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Beverages", 100},
           {"Snacks", 200}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
       worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotTables pivotTables = worksheet.getPivotTables();
       
      Returns:
      The IPivotTables collection that contains all PivotTable reports on the worksheet.
    • getRange

      IRange getRange(String reference)
      Gets the IRange object with the specified reference.

      Use this method to access a single cell, a contiguous cell range, or a non-contiguous range by using an A1-style reference string.

      
       worksheet.getRange("A1").setValue("Name");
       worksheet.getRange("B1").setValue(100);
       IRange range = worksheet.getRange("A1:B1");
       range.getInterior().setColor(Color.GetLightYellow());
       
      Parameters:
      reference - The A1-style reference string that identifies the target cell or range.
      Returns:
      The IRange object that represents the specified reference.
    • getRange

      IRange getRange(int row, int column)
      Gets the IRange object for the cell at the specified row and column.

      Use this method to access a single cell by its zero-based row and column indexes. For example, (0, 0) refers to cell A1.

      
       worksheet.getRange("A1").setValue("Name");
       IRange cell = worksheet.getRange(0, 1);
       cell.setValue(100);
       
      Parameters:
      row - The zero-based row index of the cell.
      column - The zero-based column index of the cell.
      Returns:
      The IRange object that represents the cell at the specified row and column.
    • getRange

      IRange getRange(int row, int column, int rowCount, int columnCount)
      Gets the IRange object for the specified row, column, row count, and column count.

      Use this method to access a rectangular range by its top-left cell and size.

      
       IRange range = worksheet.getRange(0, 0, 2, 2);
       range.setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       
      Parameters:
      row - The starting row of the range.
      column - The starting column of the range.
      rowCount - The number of rows in the range.
      columnCount - The number of columns in the range.
      Returns:
      The IRange object that starts at the specified row and column and spans the specified number of rows and columns.
    • getSelection

      IRange getSelection()
      Gets the current selection range on the worksheet.

      Returns an IRange that represents the currently selected cells. If the selection contains multiple areas, the returned range represents all selected areas. Returns null if the worksheet has no selection.

      
       worksheet.getRange("A1:B2").select();
       IRange selection = worksheet.getSelection();
       selection.setValue("Selected");
       
      Returns:
      The current selection range, or null if the worksheet has no selection.
    • getShapes

      IShapes getShapes()
      Gets the IShapes collection that contains all shapes on the worksheet or chart sheet.

      Use this method to access and manage drawing objects such as shapes, pictures, and charts associated with the current sheet.

      
       worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 100, 60);
       IShapes shapes = worksheet.getShapes();
       IShape shape = shapes.get(0);
       
      Returns:
      The IShapes collection for the current worksheet or chart sheet.
    • getBackgroundPictures

      IBackgroundPictures getBackgroundPictures()
      Gets the collection of background pictures on the worksheet or chart sheet.

      The returned IBackgroundPictures object provides access to all IBackgroundPicture objects associated with the sheet.

      
       IBackgroundPictures backgroundPictures = worksheet.getBackgroundPictures();
       try (InputStream stream = createSampleImageStream()) {
           IBackgroundPicture createdPicture = backgroundPictures.addPicture(stream, ImageType.PNG, 12, 18, 120, 80);
           createdPicture.setName("Watermark");
       }
       int count = backgroundPictures.getCount();
       IBackgroundPicture picture = backgroundPictures.get(0);
       IBackgroundPicture namedPicture = backgroundPictures.get("Watermark");
       
      Returns:
      The collection of background pictures on the worksheet or chart sheet.
    • getSort

      ISort getSort()
      Gets the sort settings for the current worksheet.

      Returns an ISort object that you can use to configure the sort range, sort fields, and sort orientation before calling ISort.apply().

      
       worksheet.getRange("A1:A4").setValue(new Object[][] {{5}, {3}, {4}, {2}});
       ISort sort = worksheet.getSort();
       sort.setRange(worksheet.getRange("A1:A4"));
       sort.getSortFields().add(new ValueSortField(worksheet.getRange("A1:A4")));
       sort.apply();
       
      Returns:
      The sort settings for the current worksheet.
    • getTabColor

      Color getTabColor()
      Gets the primary color of the worksheet tab.

      Use this method to retrieve the color currently applied to the tab. To change the tab color, use setTabColor(Color).

      
       worksheet.setTabColor(Color.GetBlue());
       Color tabColor = worksheet.getTabColor();
       worksheet.getRange("A1").setValue(tabColor.toString());
       
      Returns:
      The primary color of the worksheet tab.
    • setTabColor

      void setTabColor(Color value)
      Sets the primary color of the worksheet tab.
      
       worksheet.setTabColor(Color.GetBlue());
       
      Parameters:
      value - The primary color of the worksheet tab.
    • getTables

      ITables getTables()
      Gets the collection of ITable objects in the worksheet.

      Use the returned ITables collection to create, access, and manage tables defined on the current worksheet. The collection can be empty if the worksheet does not contain any tables.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Value"},
           {"Tea", 100},
           {"Coffee", 200}
       });
       ITables tables = worksheet.getTables();
       ITable salesTable = tables.add(worksheet.getRange("A1:B3"), true);
       ITable firstTable = tables.get(0);
       
      Returns:
      The ITables collection that contains all ITable objects in the worksheet.
    • getWorkbook

      IWorkbook getWorkbook()
      Gets the Workbook that contains this worksheet.

      Use this method to access workbook-level settings, collections, and operations from the current worksheet.

      
       worksheet.getRange("A1").setValue("Name");
       IWorkbook workbook = worksheet.getWorkbook();
       workbook.getWorksheets().add();
       
      Returns:
      The workbook that contains this worksheet.
    • getProtectionSettings

      IProtectionSettings getProtectionSettings()
      Gets the protection settings of the worksheet.

      Returns an IProtectionSettings object that provides access to the worksheet protection options. Changes to the returned settings take effect only when the worksheet is protected.

      
       worksheet.setProtection(true);
       IProtectionSettings protectionSettings = worksheet.getProtectionSettings();
       protectionSettings.setAllowFiltering(true);
       
      Returns:
      The IProtectionSettings object that represents the protection options of the worksheet.
    • getProtection

      boolean getProtection()
      Gets the protection status of the worksheet.

      This property indicates whether worksheet protection is enabled.

      
       worksheet.setProtection(true);
       boolean protection = worksheet.getProtection();
       
      Returns:
      true if the worksheet is protected; otherwise, false.
    • setProtection

      void setProtection(boolean value)
      Sets the protection status of the worksheet.

      This property indicates whether worksheet protection is enabled.

      
       worksheet.setProtection(true);
       
      Parameters:
      value - true if the worksheet is protected; otherwise, false.
    • getRows

      IRange getRows()
      Gets an IRange object that represents all rows in the worksheet.

      You can use the returned range to access individual rows by index and perform row-level operations.

      
       worksheet.getRange("A1").setValue("Name");
       worksheet.getRange("B1").setValue("Value");
       IRange rows = worksheet.getRows();
       IRange firstRow = rows.get(0);
       
      Returns:
      An IRange object that represents all rows in the worksheet.
    • getFreezeRow

      int getFreezeRow()
      Gets the number of frozen rows in the worksheet.

      This method returns the row position specified by freezePanes(int,int). Returns 0 if the worksheet does not have frozen panes.

      
       worksheet.freezePanes(2, 1);
       int frozenRow = worksheet.getFreezeRow();
       
      Returns:
      The number of frozen rows in the worksheet. Returns 0 if the worksheet does not have frozen panes.
    • getFreezeColumn

      int getFreezeColumn()
      Gets the number of frozen columns in the worksheet.

      This method returns the column position specified by freezePanes(int,int). Returns 0 if the worksheet does not have frozen panes.

      
       worksheet.freezePanes(1, 2);
       int frozenColumn = worksheet.getFreezeColumn();
       
      Returns:
      The number of frozen columns in the worksheet. Returns 0 if the worksheet does not have frozen panes.
    • getFrozenLineColor

      Color getFrozenLineColor()
      Gets the color of the frozen line.

      This property returns the color used to display the divider between frozen and unfrozen panes. If no frozen line color has been set, this method returns null.

      
       worksheet.freezePanes(2, 1);
       worksheet.setFrozenLineColor(Color.GetRed());
       Color frozenLineColor = worksheet.getFrozenLineColor();
       
      Returns:
      The color of the frozen line, or null if no frozen line color has been set.
    • getFreezeTrailingRow

      int getFreezeTrailingRow()
      Gets the number of trailing frozen rows in the worksheet.

      This method returns the trailing frozen row position specified by freezeTrailingPanes(int,int). Returns 0 if the worksheet does not have trailing frozen panes.

      
       worksheet.freezeTrailingPanes(2, 1);
       int trailingFrozenRow = worksheet.getFreezeTrailingRow();
       
      Returns:
      The number of trailing frozen rows in the worksheet. Returns 0 if the worksheet does not have trailing frozen panes.
    • getFreezeTrailingColumn

      int getFreezeTrailingColumn()
      Gets the number of trailing frozen columns in the worksheet.

      This method returns the trailing frozen column position specified by freezeTrailingPanes(int,int). Returns 0 if the worksheet does not have trailing frozen panes.

      
       worksheet.freezeTrailingPanes(1, 2);
       int trailingFrozenColumn = worksheet.getFreezeTrailingColumn();
       
      Returns:
      The number of trailing frozen columns in the worksheet. Returns 0 if the worksheet does not have trailing frozen panes.
    • setFrozenLineColor

      void setFrozenLineColor(Color value)
      Sets the color of the frozen line.

      Use this method to set the color used to display the divider between frozen and unfrozen panes. Pass null to clear the frozen line color setting.

      
       worksheet.freezePanes(2, 1);
       worksheet.setFrozenLineColor(Color.GetRed());
       
      Parameters:
      value - The color of the frozen line, or null to clear the frozen line color setting.
    • getSplitRow

      int getSplitRow()
      Gets the split row of the worksheet.

      This method returns the row position specified by splitPanes(int,int). Returns 0 if the worksheet does not have split panes.

      
       worksheet.splitPanes(2, 1);
       int splitRow = worksheet.getSplitRow();
       
      Returns:
      The split row position in the worksheet. Returns 0 if the worksheet does not have split panes.
    • getSplitColumn

      int getSplitColumn()
      Gets the split column of the worksheet.

      This method returns the column position specified by splitPanes(int,int). Returns 0 if the worksheet does not have split panes.

      
       worksheet.splitPanes(2, 3);
       int splitColumn = worksheet.getSplitColumn();
       
      Returns:
      The split column position in the worksheet. Returns 0 if the worksheet does not have split panes.
    • getPageSetup

      IPageSetup getPageSetup()
      Gets the IPageSetup object for this worksheet.

      The returned object provides access to page setup settings such as print area, margins, orientation, scaling, and headers and footers.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       IPageSetup pageSetup = worksheet.getPageSetup();
       pageSetup.setPrintArea("A1:B3");
       
      Returns:
      The IPageSetup object that contains the page setup settings for this worksheet.
    • getHPageBreaks

      IHPageBreaks getHPageBreaks()
      Gets the collection of horizontal page breaks within the print area.

      Use the returned IHPageBreaks collection to access existing horizontal page breaks or add new ones within the worksheet print area.

      
       worksheet.getRange("A1").setValue("Name");
       worksheet.getHPageBreaks().add(worksheet.getRange("A10"));
       IHPageBreaks pageBreaks = worksheet.getHPageBreaks();
       IHPageBreak pageBreak = pageBreaks.get(0);
       
      Returns:
      The collection of horizontal page breaks within the print area.
    • getVPageBreaks

      IVPageBreaks getVPageBreaks()
      Gets the collection of vertical page breaks within the print area.

      Use the returned IVPageBreaks collection to add, access, and manage vertical page breaks on the worksheet.

      
       worksheet.getRange("A1:F10").setValue("Data");
       IVPageBreaks pageBreaks = worksheet.getVPageBreaks();
       pageBreaks.add(worksheet.getRange("D1"));
       IVPageBreak pageBreak = pageBreaks.get(0);
       IRange location = pageBreak.getLocation();
       
      Returns:
      The collection of vertical page breaks within the print area.
    • select

      void select()
      Selects this worksheet.

      Use activate() to make this worksheet the active sheet.

      
       worksheet.setName("Data");
       IWorksheet summarySheet = workbook.getWorksheets().add();
       summarySheet.setName("Summary");
       worksheet.select();
       
    • select

      void select(boolean replace)
      Selects the worksheet.

      If replace is true, the current selection is replaced with this worksheet. If replace is false, this worksheet is added to the current selection.

      
       workbook.getWorksheets().add();
       IWorksheet sheet2 = workbook.getWorksheets().get(1);
       worksheet.select(true);
       sheet2.select(false);
       
      Parameters:
      replace - true to replace the current selection with this worksheet; false to extend the current selection to include this worksheet.
    • activate

      void activate()
      Makes this worksheet the active sheet.

      This method is equivalent to clicking the worksheet tab in the workbook UI.

      
       IWorksheet summarySheet = workbook.getWorksheets().add();
       summarySheet.setName("Summary");
       summarySheet.activate();
       
    • delete

      void delete()
      Deletes this worksheet from its workbook.

      If this worksheet is the active worksheet, another worksheet may become active after the deletion.

      
       IWorksheet summarySheet = workbook.getWorksheets().add();
       summarySheet.setName("Summary");
       worksheet.delete();
       
    • evaluate

      Object evaluate(String formula)
      Evaluates the specified Excel formula or named expression and returns the result.

      The formula is evaluated by using non-dynamic array semantics.

      
       worksheet.getRange("A1").setValue(100);
       worksheet.getRange("A2").setValue(200);
       Object result = worksheet.evaluate("=SUM(A1:A2)");
       Object nameResult = worksheet.evaluate("=ROW(A1)");
       
      Parameters:
      formula - A string containing an Excel formula, named range, or defined name to evaluate.
      Returns:
      The result of the evaluation. Returns an IRange object when the formula result is a reference, such as "=A1".
      API Note:
      Use evaluate2(String) if the formula should be evaluated by using dynamic array semantics.
    • evaluate2

      Object evaluate2(String formula)
      Evaluates the specified Excel formula or named expression and returns the result.

      The formula is evaluated by using dynamic array semantics.

      
       worksheet.getRange("A1").setValue(1);
       worksheet.getRange("A2").setValue(2);
       worksheet.getRange("A3").setValue(2);
       Object result = worksheet.evaluate2("=UNIQUE(A1:A3)");
       
      Parameters:
      formula - A string containing an Excel formula, named range, or defined name to evaluate.
      Returns:
      The evaluation result. Returns a single value for a standard formula, an Object[][] for a dynamic array formula, or an IRange object when the formula returns a reference such as "=A1:A5".
      API Note:
      Use this method when the formula should be evaluated as a dynamic array formula.
    • evaluate

      Object evaluate(String formula, IFormulaResolver resolver)
      Evaluates the specified Excel formula or named expression by using a custom formula resolver and returns the result.

      Use the resolver to supply values for custom names referenced by the formula. The calculation behavior is consistent with Excel 2019 and earlier versions.

      
       class CustomFormulaResolver implements IFormulaResolver {
           public Object evaluate(String text) {
               return "TaxRate".equals(text) ? 0.08 : null;
           }
      
           public boolean isCustomName(String text) {
               return "TaxRate".equals(text);
           }
       }
      
       IFormulaResolver resolver = new CustomFormulaResolver();
       Object result = worksheet.evaluate("=100*TaxRate", resolver);
       
      Parameters:
      formula - A string containing an Excel formula, named range, or defined name to evaluate. A leading = is allowed. Must not be null or empty.
      resolver - The custom resolver used to resolve names referenced by the formula. If null, the formula is evaluated without a custom resolver.
      Returns:
      The result of the evaluation. Returns an IRange object when the formula result is a reference, such as "=A1".
      Throws:
      InvalidFormulaException - if formula is null, empty, or not a valid formula expression.
    • showAllData

      void showAllData()
      Makes all rows in the currently filtered range visible.

      If getAutoFilter() is in use on the worksheet, this method clears the applied filter criteria and changes the filter drop-down arrows to show All.

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Name", "Value"},
           {"A", 100},
           {"B", 200},
           {"C", 120}
       });
       worksheet.getRange("A1:B4").autoFilter(1, "<150");
       worksheet.showAllData();
       
    • getUsedRange

      IRange getUsedRange()
      Gets the used range, its behavior is equivalent to getUsedRange(EnumSet.of(UsedRangeType.Axis, UsedRangeType.Data, UsedRangeType.Comment, UsedRangeType.Style, UsedRangeType.Merge)).
      
       worksheet.getRange("B2").setValue("Used cell");
       IRange usedRange = worksheet.getUsedRange();
       
      Returns:
      The used range, its behavior is equivalent to getUsedRange(EnumSet.of(UsedRangeType.Axis, UsedRangeType.Data, UsedRangeType.Comment, UsedRangeType.Style, UsedRangeType.Merge)).
    • getUsedRange

      IRange getUsedRange(EnumSet<UsedRangeType> type)
      Gets the used range for the specified feature types.
      
       worksheet.getRange("B2").setValue("Used cell");
       IRange usedRange = worksheet.getUsedRange(EnumSet.of(UsedRangeType.Data));
       
      Parameters:
      type - The feature type.
      Returns:
      the IRange object that represents the used range on the specified worksheet.
    • freezePanes

      void freezePanes(int row, int column)
      Freezes panes at the specified row and column positions.

      Use this method to keep the rows above the specified row position and the columns to the left of the specified column position visible while scrolling the worksheet.

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Name", "Value"},
           {"A", 100},
           {"B", 200},
           {"C", 300}
       });
       worksheet.freezePanes(1, 1);
       
      Parameters:
      row - The frozen row position.
      column - The frozen column position.
    • unfreezePanes

      void unfreezePanes()
      Unfreezes panes.

      This method clears the pane freeze state that was applied by freezePanes(int,int).

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Value"},
           {"A", 100},
           {"B", 200}
       });
       worksheet.freezePanes(1, 1);
       worksheet.unfreezePanes();
       
    • freezeTrailingPanes

      void freezeTrailingPanes(int row, int column)
      Sets trailing frozen panes at the specified row and column positions.

      This method sets the number of trailing rows and trailing columns that remain visible when the worksheet is scrolled.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Value"},
           {"A", 100},
           {"B", 200}
       });
       worksheet.freezeTrailingPanes(1, 1);
       
      Parameters:
      row - The trailing frozen row position.
      column - The trailing frozen column position.
    • unfreezeTrailingPanes

      void unfreezeTrailingPanes()
      Removes trailing frozen panes.

      This method clears the trailing frozen pane state that was applied by freezeTrailingPanes(int,int).

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Value"},
           {"A", 100},
           {"B", 200}
       });
       worksheet.freezeTrailingPanes(1, 1);
       worksheet.unfreezeTrailingPanes();
       
    • splitPanes

      void splitPanes(int row, int column)
      Splits the worksheet into panes at the specified row and column positions.

      Use this method to divide the worksheet view into multiple panes so that different areas of the worksheet can be viewed independently.

      
       worksheet.getRange("A1").setValue("Name");
       worksheet.getRange("B1").setValue("Value");
       worksheet.splitPanes(2, 2);
       IPanes panes = worksheet.getPanes();
       
      Parameters:
      row - The row position where the worksheet is split.
      column - The column position where the worksheet is split.
    • unsplitPanes

      void unsplitPanes()
      Removes pane splits from the worksheet.

      This method clears the current split pane layout and restores the worksheet to a single-pane view. The implementation forwards to splitPanes(int,int) with both arguments set to 0.

      
       worksheet.splitPanes(2, 2);
       worksheet.unsplitPanes();
       IPanes panes = worksheet.getPanes();
       
    • getPanes

      IPanes getPanes()
      Gets the panes in the worksheet.

      Returns the IPanes collection for the current worksheet view. Use this method to access the IPane objects in the worksheet, such as after calling splitPanes(int,int).

      
       worksheet.splitPanes(2, 2);
       IPanes panes = worksheet.getPanes();
       IPane pane = panes.get(0);
       
      Returns:
      The IPanes collection that contains the worksheet panes.
    • getActivePane

      IPane getActivePane()
      Gets the active pane of the worksheet.

      Returns the IPane object that represents the pane currently active in the worksheet view. Use this method to access or modify the scroll position of the active pane after the worksheet has been split into multiple panes.

      
       worksheet.splitPanes(2, 2);
       IPane pane = worksheet.getActivePane();
       pane.setScrollRow(3);
       pane.setScrollColumn(2);
       
      Returns:
      The IPane object that represents the active pane of the worksheet.
    • save

      void save(String fileName)
      Saves the current worksheet to the specified file.

      The file format is determined from the extension in fileName and the call is forwarded to save(String,SaveFileFormat) with the resolved format.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       worksheet.save("InvoiceSheet.xlsx");
       
      Parameters:
      fileName - The file name to save to. Must be a valid file path and include the target file name; null is not supported.
      Throws:
      IllegalArgumentException - if fileName is not a valid file path.
    • save

      void save(String fileName, SaveFileFormat fileFormat)
      Saves the current worksheet to the specified file in the specified format.

      Use this method to export a single worksheet when the target file path and file format are known explicitly.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       worksheet.save("InvoiceSheet.pdf", SaveFileFormat.Pdf);
       
      Parameters:
      fileName - The path and name of the file to create. Must be a valid file path; null is not supported.
      fileFormat - The file format to use when saving the worksheet.
    • save

      void save(OutputStream fileStream, SaveFileFormat fileFormat)
      Saves the current worksheet to the specified stream in the specified format.

      Use this method to export a single worksheet to a stream when the output format is known explicitly.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();
       worksheet.save(stream, SaveFileFormat.Pdf);
       
      Parameters:
      fileStream - The output stream to receive the saved worksheet. Must not be null.
      fileFormat - The format used to save the worksheet to the stream.
    • save

      void save(String fileName, SaveOptionsBase options)
      Saves the current worksheet to the specified file by using the specified save options.

      The save behavior depends on the concrete SaveOptionsBase instance that is provided. This overload writes the worksheet to the file path specified by fileName.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Score"},
           {"Alice", 100}
       });
       SaveOptionsBase options = new PdfSaveOptions();
       worksheet.save("report.pdf", options);
       
      Parameters:
      fileName - The path and name of the file to create. Must be a valid file path and must not be null.
      options - The save options that control how the worksheet is written. This value must not be null.
      Throws:
      IllegalArgumentException - if fileName is invalid, or if saving the worksheet fails.
      UnsupportedOperationException - if the specified save options use an unsupported file format.
    • save

      void save(OutputStream fileStream, SaveOptionsBase options)
      Saves the current worksheet to the specified stream by using the specified save options.

      The output format and save behavior are determined by the concrete SaveOptionsBase instance that is provided.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Score"},
           {"Alice", 100}
       });
       SaveOptionsBase options = new PdfSaveOptions();
       java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();
       worksheet.save(stream, options);
       
      Parameters:
      fileStream - The output stream that receives the saved worksheet. This value must not be null.
      options - The save options that control how the worksheet is written to the stream. This value must not be null.
      Throws:
      UnsupportedOperationException - if the specified save options use a file format that is not supported by worksheet stream saving.
      IllegalArgumentException - if the specified save options use an invalid or unsupported file format.
    • getFixedPageBreaks

      boolean getFixedPageBreaks()
      Gets whether the horizontal and vertical page breaks are fixed when rows or columns are inserted or deleted.

      When this property is true, existing page break positions remain fixed during row or column insertion and deletion operations.

      
       worksheet.getRange("A1:T32").setValue(1);
       IHPageBreak pageBreak = worksheet.getHPageBreaks().add(worksheet.getRows().get(7));
       worksheet.setFixedPageBreaks(true);
       boolean fixedPageBreaks = worksheet.getFixedPageBreaks();
       worksheet.getRows().get(6).insert();
       IRange location = pageBreak.getLocation();
       
      Returns:
      true if the horizontal and vertical page breaks are fixed when rows or columns are inserted or deleted; otherwise, false.
    • setFixedPageBreaks

      void setFixedPageBreaks(boolean value)
      Sets whether the horizontal and vertical page breaks are fixed when rows or columns are inserted or deleted.

      When this property is true, existing page break positions remain fixed during row or column insertion and deletion operations.

      
       worksheet.getRange("A1:T32").setValue(1);
       IHPageBreak pageBreak = worksheet.getHPageBreaks().add(worksheet.getRows().get(7));
       worksheet.setFixedPageBreaks(true);
       worksheet.getRows().get(6).insert();
       IRange location = pageBreak.getLocation();
       
      Parameters:
      value - true if the horizontal and vertical page breaks are fixed when rows or columns are inserted or deleted; otherwise, false.
    • getType

      SheetType getType()
      Gets the sheet type.

      Use this method to determine whether the current sheet is a regular worksheet or another supported sheet type, such as a chart sheet.

      
       IWorksheet chartSheet = workbook.getWorksheets().add(SheetType.Chart);
       SheetType type = chartSheet.getType();
       
      Returns:
      The sheet type.
    • getTag

      Object getTag()
      Gets the custom tag associated with the worksheet.

      Use this method to retrieve application-defined metadata stored with the worksheet. To assign a tag, use setTag(Object).

      
       worksheet.setTag("Quarterly summary");
       Object tag = worksheet.getTag();
       String text = (String) tag;
       
      Returns:
      The custom tag stored on the worksheet. Returns null if no tag has been assigned.
    • setTag

      void setTag(Object tag)
      Sets the custom tag associated with the worksheet.
      
       worksheet.setTag("Quarterly summary");
       
      Parameters:
      tag - The custom tag stored on the worksheet. Sets null if no tag has been assigned.
    • getCellType

      BaseCellType getCellType()
      Gets the cell type for the worksheet.

      Use this method to retrieve the BaseCellType applied at the worksheet level. The returned cell type affects cells that inherit the worksheet's default cell type setting.

      
       worksheet.setCellType(new ButtonCellType());
       BaseCellType cellType = worksheet.getCellType();
       
      Returns:
      The worksheet-level cell type, or null if no cell type is set for the worksheet.
    • setCellType

      void setCellType(BaseCellType cellType)
      Sets the worksheet-level cell type.

      The specified BaseCellType is used as the default cell type for cells that inherit the worksheet's cell type setting. Use null to clear the worksheet-level cell type.

      
       ButtonCellType cellType = new ButtonCellType();
       cellType.setText("Details");
       worksheet.getRange("A1").setValue("Details");
       worksheet.setCellType(cellType);
       
      Parameters:
      cellType - The cell type to apply to the worksheet. Use null to remove the worksheet-level cell type.
    • getDataSource

      Object getDataSource()
      Gets the data source used for data binding in the current worksheet.

      This method returns the object previously assigned through setDataSource(Object).

      
       JsonDataSource dataSource = new JsonDataSource("[{\"name\":\"Jack\",\"age\":12},{\"name\":\"Alice\",\"age\":25}]");
       worksheet.setAutoGenerateColumns(true);
       worksheet.setDataSource(dataSource);
       Object source = worksheet.getDataSource();
       Object firstName = worksheet.getRange("A1").getValue();
       
      Returns:
      The data source object for the current worksheet, or null if no data source has been set.
    • setDataSource

      void setDataSource(Object value)
      Sets the data source used for data binding in the current worksheet.
      
       JsonDataSource dataSource = new JsonDataSource("[{\"name\":\"Jack\",\"age\":12},{\"name\":\"Alice\",\"age\":25}]");
       worksheet.setAutoGenerateColumns(true);
       worksheet.setDataSource(dataSource);
       Object firstName = worksheet.getRange("A1").getValue();
       
      Parameters:
      value - The data source object for the current worksheet, or null if no data source has been set.
    • getAutoGenerateColumns

      boolean getAutoGenerateColumns()
      Gets whether columns are generated automatically when data is bound to the worksheet.

      When this property is true, columns can be created automatically during data binding. Use setAutoGenerateColumns(boolean) to change this setting before assigning or refreshing bound data.

      
       JsonDataSource dataSource = new JsonDataSource("[{\"name\":\"Jack\",\"age\":12},{\"name\":\"Alice\",\"age\":25}]");
       worksheet.setAutoGenerateColumns(true);
       worksheet.setDataSource(dataSource);
       boolean autoGenerateColumns = worksheet.getAutoGenerateColumns();
       int columnCount = worksheet.getColumnCount();
       Object firstName = worksheet.getRange("A1").getValue();
       Object secondAge = worksheet.getRange("B2").getValue();
       
      Returns:
      true if columns are generated automatically during data binding; otherwise, false.
    • setAutoGenerateColumns

      void setAutoGenerateColumns(boolean value)
      Sets whether columns are generated automatically when data is bound to the worksheet.
      
       JsonDataSource dataSource = new JsonDataSource("[{\"name\":\"Jack\",\"age\":12},{\"name\":\"Alice\",\"age\":25}]");
       worksheet.setAutoGenerateColumns(true);
       worksheet.setDataSource(dataSource);
       int columnCount = worksheet.getColumnCount();
       Object firstName = worksheet.getRange("A1").getValue();
       Object secondAge = worksheet.getRange("B2").getValue();
       
      Parameters:
      value - true if columns are generated automatically during data binding; otherwise, false.
    • getOutlineColumn

      IOutlineColumn getOutlineColumn()
      Gets the outline column for the worksheet.

      The outline column displays hierarchical row data in a tree view. Use the returned IOutlineColumn object to configure the column index and display options for the row hierarchy.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{"Name"}, {"Node 1"}, {"Node 1.1"}});
       worksheet.getRange("A2").setIndentLevel(1);
       IOutlineColumn outlineColumn = worksheet.getOutlineColumn();
       outlineColumn.setColumnIndex(0);
       
      Returns:
      The IOutlineColumn object for the current worksheet.
    • getScenarios

      IScenarios getScenarios()
      Gets the IScenarios object that represents the collection of What-If analysis scenarios in the worksheet.

      Use the returned collection to add, retrieve, and iterate worksheet scenarios.

      
       worksheet.getRange("C4").setValue(0.8);
       IScenarios scenarios = worksheet.getScenarios();
       scenarios.add("80% highest", worksheet.getRange("C4"));
       IScenario scenario = scenarios.get("80% highest");
       
      Returns:
      The IScenarios object for the worksheet's scenarios.
    • getAutoMergeRangesInfo

      List<IAutoMergeRangeInfo> getAutoMergeRangesInfo()
      Gets a list of IAutoMergeRangeInfo objects that represent all auto merge range information in the current worksheet.

      Each item describes an auto-merge range that was added by autoMerge(IRange), autoMerge(IRange,AutoMergeDirection), autoMerge(IRange,AutoMergeDirection,AutoMergeMode), or autoMerge(IRange,AutoMergeDirection,AutoMergeMode,AutoMergeSelectionMode).

      
       IRange range = worksheet.getRange("A1:A4");
       range.setValue(new Object[][] {
           {"North"},
           {"North"},
           {"South"},
           {"South"}
       });
       worksheet.autoMerge(range, AutoMergeDirection.Column, AutoMergeMode.Free);
       List<IAutoMergeRangeInfo> autoMergeInfos = worksheet.getAutoMergeRangesInfo();
       
      Returns:
      A list of IAutoMergeRangeInfo objects for the current worksheet. Returns an empty list if no auto merge range information exists.
    • copy

      IWorksheet copy()
      Copies the sheet to the end of the current workbook.

      The returned worksheet represents the newly created copy.

      
       worksheet.setName("Template");
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       IWorksheet copiedSheet = worksheet.copy();
       copiedSheet.setName("Template Copy");
       
      Returns:
      The newly copied worksheet.
    • copy

      IWorksheet copy(IWorkbook workbook)
      Copies the sheet to the end of the specified workbook.

      The copied sheet is appended to the destination workbook and returned as a new worksheet instance. If workbook is null, the sheet is copied to the end of the current workbook.

      
       worksheet.setName("Report");
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       IWorkbook targetWorkbook = new Workbook();
       IWorksheet copiedSheet = worksheet.copy(targetWorkbook);
       copiedSheet.setName("Report Copy");
       
      Parameters:
      workbook - The workbook to which the sheet will be copied, or null to copy the sheet to the end of the current workbook.
      Returns:
      The new copied sheet in the destination workbook.
    • copyBefore

      IWorksheet copyBefore(IWorksheet targetSheet)
      Copies the sheet to the location before the specified sheet.

      The copied sheet is inserted immediately before targetSheet. The target sheet can belong to the current workbook or another workbook.

      
       worksheet.setName("Data");
       worksheet.getRange("A1").setValue("Name");
       IWorksheet summarySheet = workbook.getWorksheets().add();
       summarySheet.setName("Summary");
       IWorksheet copiedSheet = worksheet.copyBefore(summarySheet);
       copiedSheet.setName("Data Copy");
       
      Parameters:
      targetSheet - The sheet before which the copied sheet will be placed. It can be a sheet in the same workbook or another workbook.
      Returns:
      The new copied sheet.
    • copyAfter

      IWorksheet copyAfter(IWorksheet targetSheet)
      Copies the sheet to the location after the specified sheet.

      The copied sheet is inserted immediately after targetSheet. The target sheet can belong to the current workbook or another workbook.

      
       worksheet.setName("Data");
       worksheet.getRange("A1").setValue("Name");
       IWorksheet summarySheet = workbook.getWorksheets().add();
       summarySheet.setName("Summary");
       IWorksheet copiedSheet = worksheet.copyAfter(summarySheet);
       copiedSheet.setName("Data Copy");
       
      Parameters:
      targetSheet - The sheet after which the copied sheet will be placed. It can be a sheet in the same workbook or another workbook.
      Returns:
      The new copied sheet.
    • move

      IWorksheet move()
      Moves the worksheet to the end of the current workbook.
      
       worksheet.setName("Summary");
       workbook.getWorksheets().add().setName("Details");
       IWorksheet movedSheet = worksheet.move();
       
      Returns:
      The moved worksheet.
    • move

      IWorksheet move(IWorkbook workbook)
      Moves the sheet to the end of the specified workbook.

      If workbook is null or is the current workbook, the sheet is moved to the end of the current workbook.

      
       worksheet.setName("Summary");
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       workbook.getWorksheets().add().setName("Overview");
       IWorkbook targetWorkbook = new Workbook();
       IWorksheet movedSheet = worksheet.move(targetWorkbook);
       
      Parameters:
      workbook - The workbook to which the sheet will be moved, or null to move the sheet to the end of the current workbook.
      Returns:
      The moved sheet.
    • moveBefore

      IWorksheet moveBefore(IWorksheet targetSheet)
      Moves the sheet to the location before the specified sheet.

      The target sheet can belong to the same workbook or a different workbook.

      
       worksheet.setName("Data");
       IWorksheet summarySheet = workbook.getWorksheets().add();
       summarySheet.setName("Summary");
       IWorksheet movedSheet = summarySheet.moveBefore(worksheet);
       
      Parameters:
      targetSheet - The sheet before which the moved sheet will be placed. It can be the sheet of the same or another workbook.
      Returns:
      The moved sheet.
    • moveAfter

      IWorksheet moveAfter(IWorksheet targetSheet)
      Moves the sheet to the location after the specified sheet.

      The target sheet can belong to the same workbook or another workbook.

      
       worksheet.setName("Summary");
       IWorksheet detailsSheet = workbook.getWorksheets().add();
       detailsSheet.setName("Details");
       IWorksheet movedSheet = worksheet.moveAfter(detailsSheet);
       
      Parameters:
      targetSheet - The sheet after which the moved sheet will be placed. It can be the sheet of the same or another workbook.
      Returns:
      The moved sheet.
    • toJson

      String toJson()
      Generates a JSON string from the worksheet.

      The generated JSON represents the current worksheet content and can be used with fromJson(String) to load worksheet data.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       String json = worksheet.toJson();
       
      Returns:
      The JSON string that represents the worksheet.
    • toJson

      String toJson(SerializationOptions serializationOptions)
      Generates a JSON string from the worksheet.

      Serializes the current worksheet to JSON and applies the specified SerializationOptions during serialization. If serializationOptions is null, the worksheet is serialized with internally created default options.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       SerializationOptions options = new SerializationOptions();
       options.setIgnoreStyle(true);
       String json = worksheet.toJson(options);
       
      Parameters:
      serializationOptions - The SerializationOptions object to apply during serialization; may be null.
      Returns:
      The JSON string that represents the worksheet.
    • toJson

      void toJson(OutputStream stream)
      Generates a JSON stream from the worksheet.

      Writes the worksheet content to the specified output stream in JSON format.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       ByteArrayOutputStream stream = new ByteArrayOutputStream();
       worksheet.toJson(stream);
       
      Parameters:
      stream - The output stream that receives the worksheet JSON content. Must not be null.
    • toJson

      void toJson(OutputStream stream, SerializationOptions serializationOptions)
      Generates a JSON stream from the worksheet.

      Writes the worksheet content as JSON to the specified output stream and applies the specified SerializationOptions during serialization.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       SerializationOptions options = new SerializationOptions();
       ByteArrayOutputStream stream = new ByteArrayOutputStream();
       worksheet.toJson(stream, options);
       
      Parameters:
      stream - The output stream that receives the generated JSON content.
      serializationOptions - The SerializationOptions object to apply during serialization.
    • fromJson

      void fromJson(String json)
      Generates a worksheet from the specified JSON string.

      Use this method to load worksheet content from JSON data.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       String json = worksheet.toJson();
       worksheet.fromJson(json);
       
      Parameters:
      json - The input JSON string that represents the worksheet.
    • fromJson

      void fromJson(String json, DeserializationOptions deserializationOptions)
      Generates a worksheet from the specified JSON string using the provided deserialization options.

      Use DeserializationOptions to control how the JSON data is loaded, such as whether formulas or styles are ignored and whether recalculation is prevented after loading.

      
       worksheet.getRange("A1").setValue("Sample");
       String json = worksheet.toJson();
       DeserializationOptions options = new DeserializationOptions();
       worksheet.fromJson(json, options);
       
      Parameters:
      json - The input JSON string that describes the worksheet content.
      deserializationOptions - The DeserializationOptions object that controls how the JSON is loaded.
    • fromJson

      void fromJson(InputStream stream)
      Generates a worksheet from the specified JSON stream.
      
       try (InputStream stream = new FileInputStream("workbook.json")) {
           worksheet.fromJson(stream);
       }
       
      Parameters:
      stream - The input JSON stream that describes the worksheet content.
    • fromJson

      void fromJson(InputStream stream, DeserializationOptions deserializationOptions)
      Generates a worksheet from the specified JSON stream using the provided deserialization options.
      
       DeserializationOptions options = new DeserializationOptions();
       options.setIgnoreStyle(true);
       try (InputStream stream = new FileInputStream("workbook.json")) {
           worksheet.fromJson(stream, options);
       }
       
      Parameters:
      stream - The input JSON stream that describes the worksheet content.
      deserializationOptions - The DeserializationOptions object that controls how the JSON is loaded.
    • autoMerge

      void autoMerge(IRange range)
      Applies auto merge to the specified range by using the default direction, mode, and selection mode.
      
       IRange range = worksheet.getRange("A1:A4");
       range.setValue(new Object[][] {
           {"North"},
           {"North"},
           {"South"},
           {"South"}
       });
       worksheet.autoMerge(range);
       
      Parameters:
      range - The range to apply auto merge to. null is not supported.
    • autoMerge

      void autoMerge(IRange range, AutoMergeDirection direction)
      Applies auto merge for a range. The auto merge mode is AutoMergeMode.Free. The auto merge selection mode is AutoMergeSelectionMode.Source.

      This method adds auto-merge information to the specified range so that adjacent cells with the same value can be merged automatically. If direction is AutoMergeDirection.None, the existing auto merge for the range is canceled.

      
       IRange range = worksheet.getRange("A1:A4");
       range.setValue(new Object[][] {
           {"Fruit"}, {"Fruit"}, {"Vegetable"}, {"Vegetable"}
       });
       worksheet.autoMerge(range, AutoMergeDirection.Column);
       
      Parameters:
      range - The range to which auto-merge information is applied.
      direction - The direction used to evaluate and apply auto merge. Use AutoMergeDirection.None to cancel auto merge for the range.
    • autoMerge

      void autoMerge(IRange range, AutoMergeDirection direction, AutoMergeMode mode)
      Applies auto merge for a range. The auto merge selection mode is AutoMergeSelectionMode.Source.

      This method adds auto-merge information to the specified range so that neighboring cells with the same value can be merged automatically. The auto-merge operation takes effect when the worksheet is exported with auto-merged cells included. If direction is AutoMergeDirection.None, the auto merge for the range is canceled.

      
       IRange range = worksheet.getRange("A1:B4");
       range.setValue(new Object[][] {
           {"Fruit", "Fruit"},
           {"Apple", "Apple"},
           {"Pear", "Pear"},
           {"Pear", "Pear"}
       });
       worksheet.autoMerge(range, AutoMergeDirection.Column, AutoMergeMode.Restricted);
       
      Parameters:
      range - The range to which auto-merge information is applied.
      direction - The auto merge direction. Use AutoMergeDirection.None to cancel auto merge for the range.
      mode - The auto merge mode that determines how neighboring cells with identical values are merged.
    • autoMerge

      void autoMerge(IRange range, AutoMergeDirection direction, AutoMergeMode mode, AutoMergeSelectionMode selectionMode)
      Applies auto merge to the specified range using the given direction, mode, and selection mode.

      Auto merge combines neighboring cells that have the same value within the specified range. If AutoMergeDirection.None is specified, the existing auto merge setting for the range is canceled.

      
       IRange range = worksheet.getRange("A1:B4");
       range.setValue(new Object[][] {
           {"Name", "Type"},
           {"Apple", "Fruit"},
           {"Apple", "Fruit"},
           {"Pear", "Fruit"}
       });
       worksheet.autoMerge(range, AutoMergeDirection.Column, AutoMergeMode.Restricted, AutoMergeSelectionMode.Merged);
       
      Parameters:
      range - The range to which auto merge is applied.
      direction - The direction used to evaluate and apply auto merge. Specify AutoMergeDirection.None to cancel auto merge for the range.
      mode - The mode that determines how neighboring cells with the same value are merged.
      selectionMode - The selection mode to use for cells in the auto-merged range.
    • toImage

      void toImage(String imageFile)
      Saves the worksheet to the specified image file.

      Use this method to export the current worksheet as an image.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       worksheet.toImage("worksheet.png");
       
      Parameters:
      imageFile - The path and file name of the output image file.
    • toImage

      void toImage(String imageFile, ImageSaveOptions options)
      Saves the worksheet to the specified image file using the provided save options.

      Use this method to render the current worksheet as an image and write the generated image data to imageFile. The output image format is determined by the file extension in imageFile.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       ImageSaveOptions options = new ImageSaveOptions();
       options.setShowGridlines(true);
       worksheet.toImage("worksheet.png", options);
       
      Parameters:
      imageFile - The path and file name of the output image file.
      options - The options that control how the worksheet is exported to the image; may be null.
      Throws:
      IllegalArgumentException - if an error occurs while writing the image file.
    • toImage

      void toImage(OutputStream stream, ImageType imageType)
      Saves the worksheet to the specified image stream.

      Use this method to render the current worksheet as an image in the format specified by imageType and write the generated image data to stream.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();
       worksheet.toImage(stream, ImageType.PNG);
       
      Parameters:
      stream - The output stream that receives the generated image data.
      imageType - The type of image to create.
    • toImage

      void toImage(OutputStream stream, ImageType imageType, ImageSaveOptions options)
      Saves the worksheet to the specified image stream using the provided image type and save options.

      Use this method to export the current worksheet as an image and write the generated data to an OutputStream.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"Name", "Value"},
           {"Test", 100}
       });
       java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();
       ImageSaveOptions options = new ImageSaveOptions();
       worksheet.toImage(stream, ImageType.PNG, options);
       
      Parameters:
      stream - The output stream that receives the generated image data.
      imageType - The type of image to create.
      options - The options that control image output; can be null.
      Throws:
      IllegalArgumentException - if imageType is unsupported.
    • protect

      void protect()
      Protects the worksheet so that it cannot be modified.

      The worksheet is protected without a password.

      
       worksheet.getRange("A1").setValue("Name");
       worksheet.protect();
       
    • protect

      void protect(String password)
      Protects the worksheet so that it cannot be modified.

      If password is not null or empty, the worksheet is protected with that password. Otherwise, the worksheet is protected without a password.

      
       worksheet.getRange("A1").setValue("Name");
       // Protect the worksheet with a password retrieved from a secure source
       String password = getPasswordFromSecureSource();
       worksheet.protect(password);
       
      Parameters:
      password - The password used to protect the worksheet. Specify null or an empty string to protect the worksheet without a password.
    • unprotect

      void unprotect()
      Removes worksheet protection when the worksheet was protected without a password.
      
       worksheet.getRange("A1").setValue("Name");
       worksheet.protect();
       worksheet.unprotect();
       
    • unprotect

      void unprotect(String password)
      Removes worksheet protection by using the specified password.
      
       // Protect the worksheet with a password retrieved from a secure source
       String password = getPasswordFromSecureSource();
       worksheet.protect(password);
       worksheet.unprotect(password);
       
      Parameters:
      password - The password used to remove worksheet protection. Specify the same password that was used to protect the worksheet.
      Throws:
      IllegalArgumentException - if the worksheet is password-protected and the specified password is null, empty, or incorrect.