Documentation of 'org.apache.poi.xssf.usermodel.XSSFSheet' Java class
XSSFSheet
org.apache.poi.xssf.usermodel

Class XSSFSheet

  • All Implemented Interfaces:
    java.lang.Iterable<Row>, Sheet
    Direct Known Subclasses:
    XSSFChartSheet, XSSFDialogsheet


    public class XSSFSheet
    extends POIXMLDocumentPart
    implements Sheet
    High level representation of a SpreadsheetML worksheet.

    Sheets are the central structures within a workbook, and are where a user does most of his spreadsheet work. The most common type of sheet is the worksheet, which is represented as a grid of cells. Worksheet cells can contain text, numbers, dates, and formulas. Cells can also be formatted.

    • Method Detail

      • getWorkbook

        public XSSFWorkbook getWorkbook()
        Returns the parent XSSFWorkbook
        Specified by:
        getWorkbook in interface Sheet
        Returns:
        the parent XSSFWorkbook
      • getCTWorksheet

        @Internal
        public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet getCTWorksheet()
        Provide access to the CTWorksheet bean holding this sheet's data
        Returns:
        the CTWorksheet bean holding this sheet's data
      • getSheetName

        public java.lang.String getSheetName()
        Returns the name of this sheet
        Specified by:
        getSheetName in interface Sheet
        Returns:
        the name of this sheet
      • addMergedRegion

        public int addMergedRegion(CellRangeAddress region)
        Adds a merged region of cells (hence those cells form one).
        Specified by:
        addMergedRegion in interface Sheet
        Parameters:
        region - (rowfrom/colfrom-rowto/colto) to merge
        Returns:
        index of this region
      • autoSizeColumn

        public void autoSizeColumn(int column)
        Adjusts the column width to fit the contents. This process can be relatively slow on large sheets, so this should normally only be called once per column, at the end of your processing.
        Specified by:
        autoSizeColumn in interface Sheet
        Parameters:
        column - the column index
      • autoSizeColumn

        public void autoSizeColumn(int column,
                                   boolean useMergedCells)
        Adjusts the column width to fit the contents.

        This process can be relatively slow on large sheets, so this should normally only be called once per column, at the end of your processing.

        You can specify whether the content of merged cells should be considered or ignored. Default is to ignore merged cells.
        Specified by:
        autoSizeColumn in interface Sheet
        Parameters:
        column - the column index
        useMergedCells - whether to use the contents of merged cells when calculating the width of the column
      • getDrawingPatriarch

        public XSSFDrawing getDrawingPatriarch()
        Return the sheet's existing drawing, or null if there isn't yet one. Use createDrawingPatriarch() to get or create
        Returns:
        a SpreadsheetML drawing
      • createDrawingPatriarch

        public XSSFDrawing createDrawingPatriarch()
        Create a new SpreadsheetML drawing. If this sheet already contains a drawing - return that.
        Specified by:
        createDrawingPatriarch in interface Sheet
        Returns:
        a SpreadsheetML drawing
      • createFreezePane

        public void createFreezePane(int colSplit,
                                     int rowSplit)
        Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
        Specified by:
        createFreezePane in interface Sheet
        Parameters:
        colSplit - Horizontal position of split.
        rowSplit - Vertical position of split.
      • createFreezePane

        public void createFreezePane(int colSplit,
                                     int rowSplit,
                                     int leftmostColumn,
                                     int topRow)
        Creates a split (freezepane). Any existing freezepane or split pane is overwritten.

        If both colSplit and rowSplit are zero then the existing freeze pane is removed

        Specified by:
        createFreezePane in interface Sheet
        Parameters:
        colSplit - Horizontal position of split.
        rowSplit - Vertical position of split.
        leftmostColumn - Left column visible in right pane.
        topRow - Top row visible in bottom pane
      • createComment

        @Deprecated
        public XSSFComment createComment()
        Deprecated. since Nov 2009 this method is not compatible with the common SS interfaces, use (org.apache.poi.ss.usermodel.ClientAnchor) instead
        Creates a new comment for this sheet. You still need to assign it to a cell though
      • createSplitPane

        public void createSplitPane(int xSplitPos,
                                    int ySplitPos,
                                    int leftmostColumn,
                                    int topRow,
                                    int activePane)
        Creates a split pane. Any existing freezepane or split pane is overwritten.
        Specified by:
        createSplitPane in interface Sheet
        Parameters:
        xSplitPos - Horizontal position of split (in 1/20th of a point).
        ySplitPos - Vertical position of split (in 1/20th of a point).
        topRow - Top row visible in bottom pane
        leftmostColumn - Left column visible in right pane.
        activePane - Active pane. One of: PANE_LOWER_RIGHT, PANE_UPPER_RIGHT, PANE_LOWER_LEFT, PANE_UPPER_LEFT
        See Also:
        Sheet.PANE_LOWER_LEFT, Sheet.PANE_LOWER_RIGHT, Sheet.PANE_UPPER_LEFT, Sheet.PANE_UPPER_RIGHT
      • getCellComment

        public XSSFComment getCellComment(int row,
                                          int column)
        Description copied from interface: Sheet
        Returns cell comment for the specified row and column
        Specified by:
        getCellComment in interface Sheet
        Returns:
        cell comment or null if not found
      • getHyperlink

        public XSSFHyperlink getHyperlink(int row,
                                          int column)
      • getColumnBreaks

        public int[] getColumnBreaks()
        Vertical page break information used for print layout view, page layout view, drawing print breaks in normal view, and for printing the worksheet.
        Specified by:
        getColumnBreaks in interface Sheet
        Returns:
        column indexes of all the vertical page breaks, never null
      • getColumnWidth

        public int getColumnWidth(int columnIndex)
        Get the actual column width (in units of 1/256th of a character width )

        Note, the returned value is always gerater that getDefaultColumnWidth() because the latter does not include margins. Actual column width measured as the number of characters of the maximum digit width of the numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. There are 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines.

        Specified by:
        getColumnWidth in interface Sheet
        Parameters:
        columnIndex - - the column to set (0-based)
        Returns:
        width - the width in units of 1/256th of a character width
      • getColumnWidthInPixels

        public float getColumnWidthInPixels(int columnIndex)
        Get the actual column width in pixels

        Please note, that this method works correctly only for workbooks with the default font size (Calibri 11pt for .xlsx).

        Specified by:
        getColumnWidthInPixels in interface Sheet
        Parameters:
        columnIndex - - the column to set (0-based)
        Returns:
        width in pixels
      • getDefaultColumnWidth

        public int getDefaultColumnWidth()
        Get the default column width for the sheet (if the columns do not define their own width) in characters.

        Note, this value is different from getColumnWidth(int). The latter is always greater and includes 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines.

        Specified by:
        getDefaultColumnWidth in interface Sheet
        Returns:
        column width, default value is 8
      • getDefaultRowHeight

        public short getDefaultRowHeight()
        Get the default row height for the sheet (if the rows do not define their own height) in twips (1/20 of a point)
        Specified by:
        getDefaultRowHeight in interface Sheet
        Returns:
        default row height
      • getDefaultRowHeightInPoints

        public float getDefaultRowHeightInPoints()
        Get the default row height for the sheet measued in point size (if the rows do not define their own height).
        Specified by:
        getDefaultRowHeightInPoints in interface Sheet
        Returns:
        default row height in points
      • getColumnStyle

        public CellStyle getColumnStyle(int column)
        Returns the CellStyle that applies to the given (0 based) column, or null if no style has been set for that column
        Specified by:
        getColumnStyle in interface Sheet
      • setRightToLeft

        public void setRightToLeft(boolean value)
        Sets whether the worksheet is displayed from right to left instead of from left to right.
        Specified by:
        setRightToLeft in interface Sheet
        Parameters:
        value - true for right to left, false otherwise.
      • isRightToLeft

        public boolean isRightToLeft()
        Whether the text is displayed in right-to-left mode in the window
        Specified by:
        isRightToLeft in interface Sheet
        Returns:
        whether the text is displayed in right-to-left mode in the window
      • getDisplayGuts

        public boolean getDisplayGuts()
        Get whether to display the guts or not, default value is true
        Specified by:
        getDisplayGuts in interface Sheet
        Returns:
        boolean - guts or no guts
      • setDisplayGuts

        public void setDisplayGuts(boolean value)
        Set whether to display the guts or not
        Specified by:
        setDisplayGuts in interface Sheet
        Parameters:
        value - - guts or no guts
      • isDisplayZeros

        public boolean isDisplayZeros()
        Gets the flag indicating whether the window should show 0 (zero) in cells containing zero value. When false, cells with zero value appear blank instead of showing the number zero.
        Specified by:
        isDisplayZeros in interface Sheet
        Returns:
        whether all zero values on the worksheet are displayed
      • setDisplayZeros

        public void setDisplayZeros(boolean value)
        Set whether the window should show 0 (zero) in cells containing zero value. When false, cells with zero value appear blank instead of showing the number zero.
        Specified by:
        setDisplayZeros in interface Sheet
        Parameters:
        value - whether to display or hide all zero values on the worksheet
      • getFirstRowNum

        public int getFirstRowNum()
        Gets the first row on the sheet
        Specified by:
        getFirstRowNum in interface Sheet
        Returns:
        the number of the first logical row on the sheet, zero based
      • getFitToPage

        public boolean getFitToPage()
        Flag indicating whether the Fit to Page print option is enabled.
        Specified by:
        getFitToPage in interface Sheet
        Returns:
        true
      • getOddFooter

        public Footer getOddFooter()
        Returns the odd footer. Used on all pages unless other footers also present, when used on only odd pages.
      • getEvenFooter

        public Footer getEvenFooter()
        Returns the even footer. Not there by default, but when set, used on even pages.
      • getFirstFooter

        public Footer getFirstFooter()
        Returns the first page footer. Not there by default, but when set, used on the first page.
      • getOddHeader

        public Header getOddHeader()
        Returns the odd header. Used on all pages unless other headers also present, when used on only odd pages.
      • getEvenHeader

        public Header getEvenHeader()
        Returns the even header. Not there by default, but when set, used on even pages.
      • getFirstHeader

        public Header getFirstHeader()
        Returns the first page header. Not there by default, but when set, used on the first page.
      • getHorizontallyCenter

        public boolean getHorizontallyCenter()
        Determine whether printed output for this sheet will be horizontally centered.
        Specified by:
        getHorizontallyCenter in interface Sheet
      • getLastRowNum

        public int getLastRowNum()
        Description copied from interface: Sheet
        Gets the last row on the sheet
        Specified by:
        getLastRowNum in interface Sheet
        Returns:
        last row contained n this sheet (0-based)
      • getLeftCol

        public short getLeftCol()
        Description copied from interface: Sheet
        The left col in the visible view when the sheet is first viewed after opening it in a viewer
        Specified by:
        getLeftCol in interface Sheet
        Returns:
        short indicating the rownum (0 based) of the top row
      • getMergedRegion

        public CellRangeAddress getMergedRegion(int index)
        Description copied from interface: Sheet
        Returns the merged region at the specified index
        Specified by:
        getMergedRegion in interface Sheet
        Returns:
        the merged region at the specified index
        Throws:
        java.lang.IllegalStateException - if this worksheet does not contain merged regions
      • getNumMergedRegions

        public int getNumMergedRegions()
        Returns the number of merged regions defined in this worksheet
        Specified by:
        getNumMergedRegions in interface Sheet
        Returns:
        number of merged regions in this worksheet
      • getNumHyperlinks

        public int getNumHyperlinks()
      • getPaneInformation

        public PaneInformation getPaneInformation()
        Returns the information regarding the currently configured pane (split or freeze).
        Specified by:
        getPaneInformation in interface Sheet
        Returns:
        null if no pane configured, or the pane information.
      • getPhysicalNumberOfRows

        public int getPhysicalNumberOfRows()
        Returns the number of physically defined rows (NOT the number of rows in the sheet)
        Specified by:
        getPhysicalNumberOfRows in interface Sheet
        Returns:
        the number of physically defined rows
      • getPrintSetup

        public XSSFPrintSetup getPrintSetup()
        Gets the print setup object.
        Specified by:
        getPrintSetup in interface Sheet
        Returns:
        The user model for the print setup object.
      • getProtect

        public boolean getProtect()
        Answer whether protection is enabled or disabled
        Specified by:
        getProtect in interface Sheet
        Returns:
        true => protection enabled; false => protection disabled
      • protectSheet

        public void protectSheet(java.lang.String password)
        Enables sheet protection and sets the password for the sheet. Also sets some attributes on the CTSheetProtection that correspond to the default values used by Excel
        Specified by:
        protectSheet in interface Sheet
        Parameters:
        password - to set for protection. Pass null to remove protection
      • setSheetPassword

        public void setSheetPassword(java.lang.String password,
                                     HashAlgorithm hashAlgo)
        Sets the sheet password.
        Parameters:
        password - if null, the password will be removed
        hashAlgo - if null, the password will be set as XOR password (Excel 2010 and earlier) otherwise the given algorithm is used for calculating the hash password (Excel 2013)
      • validateSheetPassword

        public boolean validateSheetPassword(java.lang.String password)
        Validate the password against the stored hash, the hashing method will be determined by the existing password attributes
        Returns:
        true, if the hashes match (... though original password may differ ...)
      • getRow

        public XSSFRow getRow(int rownum)
        Returns the logical row ( 0-based). If you ask for a row that is not defined you get a null. This is to say row 4 represents the fifth row on a sheet.
        Specified by:
        getRow in interface Sheet
        Parameters:
        rownum - row to get
        Returns:
        XSSFRow representing the rownumber or null if its not defined on the sheet
      • getRowBreaks

        public int[] getRowBreaks()
        Horizontal page break information used for print layout view, page layout view, drawing print breaks in normal view, and for printing the worksheet.
        Specified by:
        getRowBreaks in interface Sheet
        Returns:
        row indexes of all the horizontal page breaks, never null
      • getRowSumsBelow

        public boolean getRowSumsBelow()
        Flag indicating whether summary rows appear below detail in an outline, when applying an outline.

        When true a summary row is inserted below the detailed data being summarized and a new outline level is established on that row.

        When false a summary row is inserted above the detailed data being summarized and a new outline level is established on that row.

        Specified by:
        getRowSumsBelow in interface Sheet
        Returns:
        true if row summaries appear below detail in the outline
      • setRowSumsBelow

        public void setRowSumsBelow(boolean value)
        Flag indicating whether summary rows appear below detail in an outline, when applying an outline.

        When true a summary row is inserted below the detailed data being summarized and a new outline level is established on that row.

        When false a summary row is inserted above the detailed data being summarized and a new outline level is established on that row.

        Specified by:
        setRowSumsBelow in interface Sheet
        Parameters:
        value - true if row summaries appear below detail in the outline
      • getRowSumsRight

        public boolean getRowSumsRight()
        Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.

        When true a summary column is inserted to the right of the detailed data being summarized and a new outline level is established on that column.

        When false a summary column is inserted to the left of the detailed data being summarized and a new outline level is established on that column.

        Specified by:
        getRowSumsRight in interface Sheet
        Returns:
        true if col summaries appear right of the detail in the outline
      • setRowSumsRight

        public void setRowSumsRight(boolean value)
        Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.

        When true a summary column is inserted to the right of the detailed data being summarized and a new outline level is established on that column.

        When false a summary column is inserted to the left of the detailed data being summarized and a new outline level is established on that column.

        Specified by:
        setRowSumsRight in interface Sheet
        Parameters:
        value - true if col summaries appear right of the detail in the outline
      • getScenarioProtect

        public boolean getScenarioProtect()
        A flag indicating whether scenarios are locked when the sheet is protected.
        Specified by:
        getScenarioProtect in interface Sheet
        Returns:
        true => protection enabled; false => protection disabled
      • getTopRow

        public short getTopRow()
        The top row in the visible view when the sheet is first viewed after opening it in a viewer
        Specified by:
        getTopRow in interface Sheet
        Returns:
        integer indicating the rownum (0 based) of the top row
      • getVerticallyCenter

        public boolean getVerticallyCenter()
        Determine whether printed output for this sheet will be vertically centered.
        Specified by:
        getVerticallyCenter in interface Sheet
        Returns:
        whether printed output for this sheet will be vertically centered.
      • groupColumn

        public void groupColumn(int fromColumn,
                                int toColumn)
        Group between (0 based) columns
        Specified by:
        groupColumn in interface Sheet
        Parameters:
        fromColumn - beginning of the column range.
        toColumn - end of the column range.
      • groupRow

        public void groupRow(int fromRow,
                             int toRow)
        Tie a range of cell together so that they can be collapsed or expanded
        Specified by:
        groupRow in interface Sheet
        Parameters:
        fromRow - start row (0-based)
        toRow - end row (0-based)
      • isColumnBroken

        public boolean isColumnBroken(int column)
        Determines if there is a page break at the indicated column
        Specified by:
        isColumnBroken in interface Sheet
        Parameters:
        column - FIXME: Document this!
        Returns:
        FIXME: Document this!
      • isColumnHidden

        public boolean isColumnHidden(int columnIndex)
        Get the hidden state for a given column.
        Specified by:
        isColumnHidden in interface Sheet
        Parameters:
        columnIndex - - the column to set (0-based)
        Returns:
        hidden - false if the column is visible
      • isDisplayFormulas

        public boolean isDisplayFormulas()
        Gets the flag indicating whether this sheet should display formulas.
        Specified by:
        isDisplayFormulas in interface Sheet
        Returns:
        true if this sheet should display formulas.
      • setDisplayGridlines

        public void setDisplayGridlines(boolean show)
        Sets the flag indicating whether this sheet should display the lines between rows and columns to make editing and reading easier. To turn printing of gridlines use setPrintGridlines(boolean)
        Specified by:
        setDisplayGridlines in interface Sheet
        Parameters:
        show - true if this sheet should display gridlines.
        See Also:
        setPrintGridlines(boolean)
      • isDisplayRowColHeadings

        public boolean isDisplayRowColHeadings()
        Gets the flag indicating whether this sheet should display row and column headings.

        Row heading are the row numbers to the side of the sheet

        Column heading are the letters or numbers that appear above the columns of the sheet

        Specified by:
        isDisplayRowColHeadings in interface Sheet
        Returns:
        true if this sheet should display row and column headings.
      • setDisplayRowColHeadings

        public void setDisplayRowColHeadings(boolean show)
        Sets the flag indicating whether this sheet should display row and column headings.

        Row heading are the row numbers to the side of the sheet

        Column heading are the letters or numbers that appear above the columns of the sheet

        Specified by:
        setDisplayRowColHeadings in interface Sheet
        Parameters:
        show - true if this sheet should display row and column headings.
      • setPrintGridlines

        public void setPrintGridlines(boolean value)
        Turns on or off the printing of gridlines.
        Specified by:
        setPrintGridlines in interface Sheet
        Parameters:
        value - boolean to turn on or off the printing of gridlines
        See Also:
        Sheet.setPrintGridlines(boolean)
      • isRowBroken

        public boolean isRowBroken(int row)
        Tests if there is a page break at the indicated row
        Specified by:
        isRowBroken in interface Sheet
        Parameters:
        row - index of the row to test
        Returns:
        true if there is a page break at the indicated row
      • setRowBreak

        public void setRowBreak(int row)
        Sets a page break at the indicated row Breaks occur above the specified row and left of the specified column inclusive. For example, sheet.setColumnBreak(2); breaks the sheet into two parts with columns A,B,C in the first and D,E,... in the second. Simuilar, sheet.setRowBreak(2); breaks the sheet into two parts with first three rows (rownum=1...3) in the first part and rows starting with rownum=4 in the second.
        Specified by:
        setRowBreak in interface Sheet
        Parameters:
        row - the row to break, inclusive
      • removeColumnBreak

        public void removeColumnBreak(int column)
        Removes a page break at the indicated column
        Specified by:
        removeColumnBreak in interface Sheet
      • removeMergedRegion

        public void removeMergedRegion(int index)
        Removes a merged region of cells (hence letting them free)
        Specified by:
        removeMergedRegion in interface Sheet
        Parameters:
        index - of the region to unmerge
      • removeMergedRegions

        public void removeMergedRegions(java.util.Set<java.lang.Integer> indices)
        Removes a number of merged regions of cells (hence letting them free) This method can be used to bulk-remove merged regions in a way much faster than calling removeMergedRegion() for every single merged region.
        Parameters:
        indices - A set of the regions to unmerge
      • removeRow

        public void removeRow(Row row)
        Remove a row from this sheet. All cells contained in the row are removed as well
        Specified by:
        removeRow in interface Sheet
        Parameters:
        row - the row to remove.
      • removeRowBreak

        public void removeRowBreak(int row)
        Removes the page break at the indicated row
        Specified by:
        removeRowBreak in interface Sheet
      • setForceFormulaRecalculation

        public void setForceFormulaRecalculation(boolean value)
        Control if Excel should be asked to recalculate all formulas on this sheet when the workbook is opened.

        Calculating the formula values with FormulaEvaluator is the recommended solution, but this may be used for certain cases where evaluation in POI is not possible.

        It is recommended to force recalcuation of formulas on workbook level using Workbook.setForceFormulaRecalculation(boolean) to ensure that all cross-worksheet formuals and external dependencies are updated.

        Specified by:
        setForceFormulaRecalculation in interface Sheet
        Parameters:
        value - true if the application will perform a full recalculation of this worksheet values when the workbook is opened
        See Also:
        Workbook.setForceFormulaRecalculation(boolean)
      • getForceFormulaRecalculation

        public boolean getForceFormulaRecalculation()
        Whether Excel will be asked to recalculate all formulas when the workbook is opened.
        Specified by:
        getForceFormulaRecalculation in interface Sheet
      • rowIterator

        public java.util.Iterator<Row> rowIterator()
        Description copied from interface: Sheet
        Returns an iterator of the physical rows
        Specified by:
        rowIterator in interface Sheet
        Returns:
        an iterator of the PHYSICAL rows. Meaning the 3rd element may not be the third row if say for instance the second row is undefined. Call getRowNum() on each row if you care which one it is.
      • iterator

        public java.util.Iterator<Row> iterator()
        Alias for rowIterator() to allow foreach loops
        Specified by:
        iterator in interface java.lang.Iterable<Row>
      • getAutobreaks

        public boolean getAutobreaks()
        Flag indicating whether the sheet displays Automatic Page Breaks.
        Specified by:
        getAutobreaks in interface Sheet
        Returns:
        true if the sheet displays Automatic Page Breaks.
      • setAutobreaks

        public void setAutobreaks(boolean value)
        Flag indicating whether the sheet displays Automatic Page Breaks.
        Specified by:
        setAutobreaks in interface Sheet
        Parameters:
        value - true if the sheet displays Automatic Page Breaks.
      • setColumnBreak

        public void setColumnBreak(int column)
        Sets a page break at the indicated column. Breaks occur above the specified row and left of the specified column inclusive. For example, sheet.setColumnBreak(2); breaks the sheet into two parts with columns A,B,C in the first and D,E,... in the second. Simuilar, sheet.setRowBreak(2); breaks the sheet into two parts with first three rows (rownum=1...3) in the first part and rows starting with rownum=4 in the second.
        Specified by:
        setColumnBreak in interface Sheet
        Parameters:
        column - the column to break, inclusive
      • setColumnGroupCollapsed

        public void setColumnGroupCollapsed(int columnNumber,
                                            boolean collapsed)
        Description copied from interface: Sheet
        Expands or collapses a column group.
        Specified by:
        setColumnGroupCollapsed in interface Sheet
        Parameters:
        columnNumber - One of the columns in the group.
        collapsed - true = collapse group, false = expand group.
      • setColumnHidden

        public void setColumnHidden(int columnIndex,
                                    boolean hidden)
        Get the visibility state for a given column.
        Specified by:
        setColumnHidden in interface Sheet
        Parameters:
        columnIndex - - the column to get (0-based)
        hidden - - the visiblity state of the column
      • setColumnWidth

        public void setColumnWidth(int columnIndex,
                                   int width)
        Set the width (in units of 1/256th of a character width)

        The maximum column width for an individual cell is 255 characters. This value represents the number of characters that can be displayed in a cell that is formatted with the standard font (first font in the workbook).

        Character width is defined as the maximum digit width of the numbers 0, 1, 2, ... 9 as rendered using the default font (first font in the workbook).
        Unless you are using a very special font, the default character is '0' (zero), this is true for Arial (default font font in HSSF) and Calibri (default font in XSSF)

        Please note, that the width set by this method includes 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines (Section 3.3.1.12 of the OOXML spec). This results is a slightly less value of visible characters than passed to this method (approx. 1/2 of a character).

        To compute the actual number of visible characters, Excel uses the following formula (Section 3.3.1.12 of the OOXML spec):

        width = Truncate([{Number of Visible Characters} * {Maximum Digit Width} + {5 pixel padding}]/{Maximum Digit Width}*256)/256

        Using the Calibri font as an example, the maximum digit width of 11 point font size is 7 pixels (at 96 dpi). If you set a column width to be eight characters wide, e.g. setColumnWidth(columnIndex, 8*256), then the actual value of visible characters (the value shown in Excel) is derived from the following equation: Truncate([numChars*7+5]/7*256)/256 = 8; which gives 7.29.

        Specified by:
        setColumnWidth in interface Sheet
        Parameters:
        columnIndex - - the column to set (0-based)
        width - - the width in units of 1/256th of a character width
        Throws:
        java.lang.IllegalArgumentException - if width > 255*256 (the maximum column width in Excel is 255 characters)
      • setDefaultColumnStyle

        public void setDefaultColumnStyle(int column,
                                          CellStyle style)
        Description copied from interface: Sheet
        Sets the default column style for a given column. POI will only apply this style to new cells added to the sheet.
        Specified by:
        setDefaultColumnStyle in interface Sheet
        Parameters:
        column - the column index
        style - the style to set
      • setDefaultColumnWidth

        public void setDefaultColumnWidth(int width)
        Specifies the number of characters of the maximum digit width of the normal style's font. This value does not include margin padding or extra padding for gridlines. It is only the number of characters.
        Specified by:
        setDefaultColumnWidth in interface Sheet
        Parameters:
        width - the number of characters. Default value is 8.
      • setDefaultRowHeight

        public void setDefaultRowHeight(short height)
        Set the default row height for the sheet (if the rows do not define their own height) in twips (1/20 of a point)
        Specified by:
        setDefaultRowHeight in interface Sheet
        Parameters:
        height - default row height in twips (1/20 of a point)
      • setDefaultRowHeightInPoints

        public void setDefaultRowHeightInPoints(float height)
        Sets default row height measured in point size.
        Specified by:
        setDefaultRowHeightInPoints in interface Sheet
        Parameters:
        height - default row height measured in point size.
      • setDisplayFormulas

        public void setDisplayFormulas(boolean show)
        Sets the flag indicating whether this sheet should display formulas.
        Specified by:
        setDisplayFormulas in interface Sheet
        Parameters:
        show - true if this sheet should display formulas.
      • setFitToPage

        public void setFitToPage(boolean b)
        Flag indicating whether the Fit to Page print option is enabled.
        Specified by:
        setFitToPage in interface Sheet
        Parameters:
        b - true if the Fit to Page print option is enabled.
      • setHorizontallyCenter

        public void setHorizontallyCenter(boolean value)
        Center on page horizontally when printing.
        Specified by:
        setHorizontallyCenter in interface Sheet
        Parameters:
        value - whether to center on page horizontally when printing.
      • setVerticallyCenter

        public void setVerticallyCenter(boolean value)
        Whether the output is vertically centered on the page.
        Specified by:
        setVerticallyCenter in interface Sheet
        Parameters:
        value - true to vertically center, false otherwise.
      • setRowGroupCollapsed

        public void setRowGroupCollapsed(int rowIndex,
                                         boolean collapse)
        group the row It is possible for collapsed to be false and yet still have the rows in question hidden. This can be achieved by having a lower outline level collapsed, thus hiding all the child rows. Note that in this case, if the lowest level were expanded, the middle level would remain collapsed.
        Specified by:
        setRowGroupCollapsed in interface Sheet
        Parameters:
        rowIndex - - the row involved, 0 based
        collapse - - boolean value for collapse
      • findEndOfRowOutlineGroup

        public int findEndOfRowOutlineGroup(int row)
        Parameters:
        row - the zero based row index to find from
      • setZoom

        public void setZoom(int numerator,
                            int denominator)
        Sets the zoom magnication for the sheet. The zoom is expressed as a fraction. For example to express a zoom of 75% use 3 for the numerator and 4 for the denominator.
        Specified by:
        setZoom in interface Sheet
        Parameters:
        numerator - The numerator for the zoom magnification.
        denominator - The denominator for the zoom magnification.
        See Also:
        setZoom(int)
      • setZoom

        public void setZoom(int scale)
        Window zoom magnification for current view representing percent values. Valid values range from 10 to 400. Horizontal & Vertical scale together. For example:
         10 - 10%
         20 - 20%
         ...
         100 - 100%
         ...
         400 - 400%
         
        Current view can be Normal, Page Layout, or Page Break Preview.
        Parameters:
        scale - window zoom magnification
        Throws:
        java.lang.IllegalArgumentException - if scale is invalid
      • shiftRows

        public void shiftRows(int startRow,
                              int endRow,
                              int n)
        Shifts rows between startRow and endRow n number of rows. If you use a negative number, it will shift rows up. Code ensures that rows don't wrap around. Calls shiftRows(startRow, endRow, n, false, false);

        Additionally shifts merged regions that are completely defined in these rows (ie. merged 2 cells on a row to be shifted).

        Specified by:
        shiftRows in interface Sheet
        Parameters:
        startRow - the row to start shifting
        endRow - the row to end shifting
        n - the number of rows to shift
      • shiftRows

        public void shiftRows(int startRow,
                              int endRow,
                              int n,
                              boolean copyRowHeight,
                              boolean resetOriginalRowHeight)
        Shifts rows between startRow and endRow n number of rows. If you use a negative number, it will shift rows up. Code ensures that rows don't wrap around

        Additionally shifts merged regions that are completely defined in these rows (ie. merged 2 cells on a row to be shifted).

        Specified by:
        shiftRows in interface Sheet
        Parameters:
        startRow - the row to start shifting
        endRow - the row to end shifting
        n - the number of rows to shift
        copyRowHeight - whether to copy the row height during the shift
        resetOriginalRowHeight - whether to set the original row's height to the default
      • showInPane

        public void showInPane(int toprow,
                               int leftcol)
        Location of the top left visible cell Location of the top left visible cell in the bottom right pane (when in Left-to-Right mode).
        Specified by:
        showInPane in interface Sheet
        Parameters:
        toprow - the top row to show in desktop window pane
        leftcol - the left column to show in desktop window pane
      • showInPane

        @Deprecated
        public void showInPane(short toprow,
                                           short leftcol)
        Deprecated. Use showInPane(int, int) as there can be more than 32767 rows.
        Location of the top left visible cell Location of the top left visible cell in the bottom right pane (when in Left-to-Right mode).
        Specified by:
        showInPane in interface Sheet
        Parameters:
        toprow - the top row to show in desktop window pane
        leftcol - the left column to show in desktop window pane
      • ungroupColumn

        public void ungroupColumn(int fromColumn,
                                  int toColumn)
        Description copied from interface: Sheet
        Ungroup a range of columns that were previously groupped
        Specified by:
        ungroupColumn in interface Sheet
        Parameters:
        fromColumn - start column (0-based)
        toColumn - end column (0-based)
      • ungroupRow

        public void ungroupRow(int fromRow,
                               int toRow)
        Ungroup a range of rows that were previously groupped
        Specified by:
        ungroupRow in interface Sheet
        Parameters:
        fromRow - start row (0-based)
        toRow - end row (0-based)
      • isSelected

        public boolean isSelected()
        Returns a flag indicating whether this sheet is selected.

        When only 1 sheet is selected and active, this value should be in synch with the activeTab value. In case of a conflict, the Start Part setting wins and sets the active sheet tab.

        Note: multiple sheets can be selected, but only one sheet can be active at one time.
        Specified by:
        isSelected in interface Sheet
        Returns:
        true if this sheet is selected
      • setSelected

        public void setSelected(boolean value)
        Sets a flag indicating whether this sheet is selected.

        When only 1 sheet is selected and active, this value should be in synch with the activeTab value. In case of a conflict, the Start Part setting wins and sets the active sheet tab.

        Note: multiple sheets can be selected, but only one sheet can be active at one time.
        Specified by:
        setSelected in interface Sheet
        Parameters:
        value - true if this sheet is selected
        See Also:
        Workbook.setActiveSheet(int)
      • addHyperlink

        @Internal
        public void addHyperlink(XSSFHyperlink hyperlink)
        Register a hyperlink in the collection of hyperlinks on this sheet
        Parameters:
        hyperlink - the link to add
      • removeHyperlink

        @Internal
        public void removeHyperlink(int row,
                                              int column)
        Removes a hyperlink in the collection of hyperlinks on this sheet
        Parameters:
        row - row index
        column - column index
      • getActiveCell

        public java.lang.String getActiveCell()
        Return location of the active cell, e.g. A1.
        Returns:
        the location of the active cell.
      • setActiveCell

        public void setActiveCell(java.lang.String cellRef)
        Sets location of the active cell
        Parameters:
        cellRef - the location of the active cell, e.g. A1..
      • hasComments

        public boolean hasComments()
        Does this sheet have any comments on it? We need to know, so we can decide about writing it to disk or not
      • getSharedFormula

        @Internal
        public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula getSharedFormula(int sid)
        Return a master shared formula by index
        Parameters:
        sid - shared group index
        Returns:
        a CTCellFormula bean holding shared formula or null if not found
      • isAutoFilterLocked

        public boolean isAutoFilterLocked()
        Returns:
        true when Autofilters are locked and the sheet is protected.
      • isDeleteColumnsLocked

        public boolean isDeleteColumnsLocked()
        Returns:
        true when Deleting columns is locked and the sheet is protected.
      • isDeleteRowsLocked

        public boolean isDeleteRowsLocked()
        Returns:
        true when Deleting rows is locked and the sheet is protected.
      • isFormatCellsLocked

        public boolean isFormatCellsLocked()
        Returns:
        true when Formatting cells is locked and the sheet is protected.
      • isFormatColumnsLocked

        public boolean isFormatColumnsLocked()
        Returns:
        true when Formatting columns is locked and the sheet is protected.
      • isFormatRowsLocked

        public boolean isFormatRowsLocked()
        Returns:
        true when Formatting rows is locked and the sheet is protected.
      • isInsertColumnsLocked

        public boolean isInsertColumnsLocked()
        Returns:
        true when Inserting columns is locked and the sheet is protected.
      • isInsertHyperlinksLocked

        public boolean isInsertHyperlinksLocked()
        Returns:
        true when Inserting hyperlinks is locked and the sheet is protected.
      • isInsertRowsLocked

        public boolean isInsertRowsLocked()
        Returns:
        true when Inserting rows is locked and the sheet is protected.
      • isPivotTablesLocked

        public boolean isPivotTablesLocked()
        Returns:
        true when Pivot tables are locked and the sheet is protected.
      • isSortLocked

        public boolean isSortLocked()
        Returns:
        true when Sorting is locked and the sheet is protected.
      • isObjectsLocked

        public boolean isObjectsLocked()
        Returns:
        true when Objects are locked and the sheet is protected.
      • isScenariosLocked

        public boolean isScenariosLocked()
        Returns:
        true when Scenarios are locked and the sheet is protected.
      • isSelectLockedCellsLocked

        public boolean isSelectLockedCellsLocked()
        Returns:
        true when Selection of locked cells is locked and the sheet is protected.
      • isSelectUnlockedCellsLocked

        public boolean isSelectUnlockedCellsLocked()
        Returns:
        true when Selection of unlocked cells is locked and the sheet is protected.
      • isSheetLocked

        public boolean isSheetLocked()
        Returns:
        true when Sheet is Protected.
      • enableLocking

        public void enableLocking()
        Enable sheet protection
      • disableLocking

        public void disableLocking()
        Disable sheet protection
      • lockAutoFilter

        public void lockAutoFilter()
        Deprecated. use lockAutoFilter(boolean)
        Enable Autofilters locking.
      • lockAutoFilter

        public void lockAutoFilter(boolean enabled)
        Enable or disable Autofilters locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockDeleteColumns

        public void lockDeleteColumns()
        Enable Deleting columns locking.
      • lockDeleteColumns

        public void lockDeleteColumns(boolean enabled)
        Enable or disable Deleting columns locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockDeleteRows

        public void lockDeleteRows()
        Deprecated. use lockDeleteRows(boolean)
        Enable Deleting rows locking.
      • lockDeleteRows

        public void lockDeleteRows(boolean enabled)
        Enable or disable Deleting rows locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockFormatCells

        public void lockFormatCells()
        Deprecated. use lockFormatCells(boolean)
        Enable Formatting cells locking.
      • lockFormatCells

        public void lockFormatCells(boolean enabled)
        Enable or disable Formatting cells locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockFormatColumns

        public void lockFormatColumns()
        Enable Formatting columns locking.
      • lockFormatColumns

        public void lockFormatColumns(boolean enabled)
        Enable or disable Formatting columns locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockFormatRows

        public void lockFormatRows()
        Deprecated. use lockFormatRows(boolean)
        Enable Formatting rows locking.
      • lockFormatRows

        public void lockFormatRows(boolean enabled)
        Enable or disable Formatting rows locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockInsertColumns

        public void lockInsertColumns()
        Enable Inserting columns locking.
      • lockInsertColumns

        public void lockInsertColumns(boolean enabled)
        Enable or disable Inserting columns locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockInsertHyperlinks

        public void lockInsertHyperlinks(boolean enabled)
        Enable or disable Inserting hyperlinks locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockInsertRows

        public void lockInsertRows()
        Deprecated. use lockInsertRows(boolean)
        Enable Inserting rows locking.
      • lockInsertRows

        public void lockInsertRows(boolean enabled)
        Enable or disable Inserting rows locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockPivotTables

        public void lockPivotTables()
        Deprecated. use lockPivotTables(boolean)
        Enable Pivot Tables locking.
      • lockPivotTables

        public void lockPivotTables(boolean enabled)
        Enable or disable Pivot Tables locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockSort

        public void lockSort()
        Deprecated. use lockSort(boolean)
        Enable Sort locking.
      • lockSort

        public void lockSort(boolean enabled)
        Enable or disable Sort locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockObjects

        public void lockObjects()
        Deprecated. use lockObjects(boolean)
        Enable Objects locking.
      • lockObjects

        public void lockObjects(boolean enabled)
        Enable or disable Objects locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockScenarios

        public void lockScenarios()
        Deprecated. use lockScenarios(boolean)
        Enable Scenarios locking.
      • lockScenarios

        public void lockScenarios(boolean enabled)
        Enable or disable Scenarios locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockSelectLockedCells

        public void lockSelectLockedCells()
        Enable Selection of locked cells locking.
      • lockSelectLockedCells

        public void lockSelectLockedCells(boolean enabled)
        Enable or disable Selection of locked cells locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • lockSelectUnlockedCells

        public void lockSelectUnlockedCells(boolean enabled)
        Enable or disable Selection of unlocked cells locking. This does not modify sheet protection status. To enforce this un-/locking, call disableLocking() or enableLocking()
      • setArrayFormula

        public CellRange<XSSFCell> setArrayFormula(java.lang.String formula,
                                                   CellRangeAddress range)
        Description copied from interface: Sheet
        Sets array formula to specified region for result.
        Specified by:
        setArrayFormula in interface Sheet
        Parameters:
        formula - text representation of the formula
        range - Region of array formula for result.
        Returns:
        the CellRange of cells affected by this change
      • removeArrayFormula

        public CellRange<XSSFCell> removeArrayFormula(Cell cell)
        Description copied from interface: Sheet
        Remove a Array Formula from this sheet. All cells contained in the Array Formula range are removed as well
        Specified by:
        removeArrayFormula in interface Sheet
        Parameters:
        cell - any cell within Array Formula range
        Returns:
        the CellRange of cells affected by this change
      • getDataValidations

        public java.util.List<XSSFDataValidation> getDataValidations()
        Description copied from interface: Sheet
        Returns the list of DataValidation in the sheet.
        Specified by:
        getDataValidations in interface Sheet
        Returns:
        list of DataValidation in the sheet
      • addValidationData

        public void addValidationData(DataValidation dataValidation)
        Description copied from interface: Sheet
        Creates a data validation object
        Specified by:
        addValidationData in interface Sheet
        Parameters:
        dataValidation - The Data validation object settings
      • createTable

        public XSSFTable createTable()
        Creates a new Table, and associates it with this Sheet
      • getTables

        public java.util.List<XSSFTable> getTables()
        Returns any tables associated with this Sheet
      • setTabColor

        public void setTabColor(int colorIndex)
        Set background color of the sheet tab
        Parameters:
        colorIndex - the indexed color to set, must be a constant from IndexedColors
      • getRepeatingRows

        public CellRangeAddress getRepeatingRows()
        Description copied from interface: Sheet
        Gets the repeating rows used when printing the sheet, as found in File->PageSetup->Sheet.

        Repeating rows cover a range of contiguous rows, e.g.:

         Sheet1!$1:$1
         Sheet2!$5:$8
         
        The CellRangeAddress returned contains a column part which spans all columns, and a row part which specifies the contiguous range of repeating rows.

        If the Sheet does not have any repeating rows defined, null is returned.

        Specified by:
        getRepeatingRows in interface Sheet
        Returns:
        an CellRangeAddress containing the repeating rows for the Sheet, or null.
      • getRepeatingColumns

        public CellRangeAddress getRepeatingColumns()
        Description copied from interface: Sheet
        Gets the repeating columns used when printing the sheet, as found in File->PageSetup->Sheet.

        Repeating columns cover a range of contiguous columns, e.g.:

         Sheet1!$A:$A
         Sheet2!$C:$F
         
        The CellRangeAddress returned contains a row part which spans all rows, and a column part which specifies the contiguous range of repeating columns.

        If the Sheet does not have any repeating columns defined, null is returned.

        Specified by:
        getRepeatingColumns in interface Sheet
        Returns:
        an CellRangeAddress containing the repeating columns for the Sheet, or null.
      • setRepeatingRows

        public void setRepeatingRows(CellRangeAddress rowRangeRef)
        Description copied from interface: Sheet
        Sets the repeating rows used when printing the sheet, as found in File->PageSetup->Sheet.

        Repeating rows cover a range of contiguous rows, e.g.:

         Sheet1!$1:$1
         Sheet2!$5:$8
        The parameter CellRangeAddress should specify a column part which spans all columns, and a row part which specifies the contiguous range of repeating rows, e.g.:
         sheet.setRepeatingRows(CellRangeAddress.valueOf("2:3"));
        A null parameter value indicates that repeating rows should be removed from the Sheet:
         sheet.setRepeatingRows(null);
        Specified by:
        setRepeatingRows in interface Sheet
        Parameters:
        rowRangeRef - a CellRangeAddress containing the repeating rows for the Sheet, or null.
      • setRepeatingColumns

        public void setRepeatingColumns(CellRangeAddress columnRangeRef)
        Description copied from interface: Sheet
        Sets the repeating columns used when printing the sheet, as found in File->PageSetup->Sheet.

        Repeating columns cover a range of contiguous columns, e.g.:

         Sheet1!$A:$A
         Sheet2!$C:$F
        The parameter CellRangeAddress should specify a row part which spans all rows, and a column part which specifies the contiguous range of repeating columns, e.g.:
         sheet.setRepeatingColumns(CellRangeAddress.valueOf("B:C"));
        A null parameter value indicates that repeating columns should be removed from the Sheet:
         sheet.setRepeatingColumns(null);
        Specified by:
        setRepeatingColumns in interface Sheet
        Parameters:
        columnRangeRef - a CellRangeAddress containing the repeating columns for the Sheet, or null.
      • createPivotTable

        @Beta
        public XSSFPivotTable createPivotTable(AreaReference source,
                                                     CellReference position,
                                                     Sheet sourceSheet)
        Create a pivot table and set area of source, source sheet and a position for pivot table
        Parameters:
        source - Area from where data will be collected
        position - A reference to the cell where the table will start
        sourceSheet - The sheet where source will be collected from
        Returns:
        The pivot table
      • createPivotTable

        @Beta
        public XSSFPivotTable createPivotTable(AreaReference source,
                                                     CellReference position)
        Create a pivot table and set area of source and a position for pivot table
        Parameters:
        source - Area from where data will be collected
        position - A reference to the cell where the table will start
        Returns:
        The pivot table
      • getPivotTables

        @Beta
        public java.util.List<XSSFPivotTable> getPivotTables()
        Returns all the pivot tables for this Sheet
      • getColumnOutlineLevel

        public int getColumnOutlineLevel(int columnIndex)
        Description copied from interface: Sheet
        Returns the column outline level. Increased as you put it into more groups (outlines), reduced as you take it out of them.
        Specified by:
        getColumnOutlineLevel in interface Sheet

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.