Class Worksheet

    • Field Detail

      • MAX_ROWS

        public static final int MAX_ROWS
        Maximum number of rows in Excel.
        See Also:
        Constant Field Values
      • MAX_COLS

        public static final int MAX_COLS
        Maximum number of columns in Excel.
        See Also:
        Constant Field Values
      • MAX_COL_WIDTH

        public static final int MAX_COL_WIDTH
        Maximum column width in Excel.
        See Also:
        Constant Field Values
      • DEFAULT_COL_WIDTH

        public static final double DEFAULT_COL_WIDTH
        Default column width in Excel.
        See Also:
        Constant Field Values
      • MAX_ROW_HEIGHT

        public static final double MAX_ROW_HEIGHT
        Maximum row height in Excel.
        See Also:
        Constant Field Values
    • Method Detail

      • getName

        public String getName()
        Get worksheet name.
        Returns:
        Worksheet name.
      • getRepeatingRows

        public org.dhatim.fastexcel.RepeatRowRange getRepeatingRows()
        Get repeating rows defined for the print setup.
        Returns:
        List representing a range of rows to be repeated on each page when printing.
      • getAutoFilterRange

        public Range getAutoFilterRange()
        Get cell range that autofilter is applied to.
        Returns:
        Range of cells that autofilter is set to (null if autofilter is not set).
      • getRepeatingCols

        public org.dhatim.fastexcel.RepeatColRange getRepeatingCols()
        Get repeating cols defined for the print setup.
        Returns:
        List representing a range of columns to be repeated on each page when printing.
      • getNamedRanges

        public Map<String,​Range> getNamedRanges()
        Get a list of named ranges.
        Returns:
        Map containing named range entries where keys are the names and values are cell ranges.
      • getWorkbook

        public Workbook getWorkbook()
        Get parent workbook.
        Returns:
        Parent workbook.
      • setVisibilityState

        public void setVisibilityState​(VisibilityState visibilityState)
        Sets the visibility state of the sheet

        This is done by setting the state attribute in the workbook.xml.

        Parameters:
        visibilityState - New visibility state for this sheet.
      • hideRow

        public void hideRow​(int row)
        Hide the given row.
        Parameters:
        row - Zero-based row number
      • showRow

        public void showRow​(int row)
        Show the given row.
        Parameters:
        row - Zero-based row number
      • hideColumn

        public void hideColumn​(int column)
        Hide the given column.
        Parameters:
        column - Zero-based column number
      • showColumn

        public void showColumn​(int column)
        Show the given column.
        Parameters:
        column - Zero-based column number
      • keepInActiveTab

        public void keepInActiveTab()
        Keep this sheet in active tab.
      • protect

        public void protect​(String password)
        Protects the sheet with a password. This method protects all the default SheetProtectionOptions and 'sheet'. (Note that this is not very secure and only meant for discouraging changes.)
        Parameters:
        password - The password to use.
      • protect

        public void protect​(String password,
                            SheetProtectionOption... options)
        Protects the sheet with a password. (Note that this is not very secure and only meant for discouraging changes.)
        Parameters:
        password - The password to use.
        options - An array of all the SheetProtectionOptions to protect.
      • protect

        public void protect​(String password,
                            Set<SheetProtectionOption> options)
        Protects the sheet with a password. (Note that this is not very secure and only meant for discouraging changes.)
        Parameters:
        password - The password to use.
        options - A Set of all the SheetProtectionOptions to protect.
      • setAutoFilter

        public void setAutoFilter​(int topRowNumber,
                                  int leftCellNumber,
                                  int bottomRowNumber,
                                  int rightCellNumber)
        Applies autofilter specifically to the given cell range
        Parameters:
        topRowNumber - The first row (header) where filter will be initialized
        leftCellNumber - Left cell number where filter will be initialized
        bottomRowNumber - The last row (containing values) that will be included
        rightCellNumber - Right cell number where filter will be initialized
      • setAutoFilter

        public void setAutoFilter​(int rowNumber,
                                  int leftCellNumber,
                                  int rightCellNumber)
        Applies autofilter automatically based on provided header cells
        Parameters:
        rowNumber - Row number
        leftCellNumber - Left cell number where filter will be initialized
        rightCellNumber - Right cell number where filter will be initialized
      • removeAutoFilter

        public void removeAutoFilter()
        Removes auto filter from sheet. Does nothing if there wasn't any filter
      • width

        public void width​(int c,
                          double width)
        Specify the width for the given column. Will autoSize by default.

        The maximum column width in excel is 255. The colum width in excel is the number of characters that can be displayed with the standard font (first font in the workbook).

        Note: The xml spec specifies additional padding for each cell (Section 3.3.1.12 of the OOXML spec) which will result in slightly less characters being displayed then what is given here.

        Parameters:
        c - Zero-based column number
        width - The width of the column in character widths
      • rowHeight

        public void rowHeight​(int r,
                              double height)
        Specify the custom row height for a row

        The maximum value for row height is 409.5

        Parameters:
        r - Zero-based row number
        height - New row height
      • value

        public void value​(int r,
                          int c,
                          String value)
        Set the cell value at the given coordinates.
        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        value - Cell value.
      • value

        public void value​(int r,
                          int c,
                          Number value)
        Set the cell value at the given coordinates.
        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        value - Cell value.
      • value

        public void value​(int r,
                          int c,
                          Boolean value)
        Set the cell value at the given coordinates.
        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        value - Cell value.
      • value

        public void value​(int r,
                          int c,
                          Date value)
        Set the cell value at the given coordinates.
        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        value - Cell value. Note Excel timestamps do not carry any timezone information; Date values are converted to an Excel serial number with the system timezone. If you need a specific timezone, prefer passing a ZonedDateTime.
      • value

        public void value​(int r,
                          int c,
                          LocalDateTime value)
        Set the cell value at the given coordinates.
        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        value - Cell value. Note Excel timestamps do not carry any timezone information; Date values are converted to an Excel serial number with the system timezone. If you need a specific timezone, prefer passing a ZonedDateTime.
      • value

        public void value​(int r,
                          int c,
                          LocalDate value)
        Set the cell value at the given coordinates.
        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        value - Cell value. Note Excel timestamps do not carry any timezone information; Date values are converted to an Excel serial number with the system timezone. If you need a specific timezone, prefer passing a ZonedDateTime.
      • value

        public void value​(int r,
                          int c,
                          ZonedDateTime value)
        Set the cell value at the given coordinates.
        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        value - Cell value.
      • value

        public Object value​(int r,
                            int c)
        Get the cell value (or formula) at the given coordinates.
        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        Returns:
        Cell value (or Formula).
      • hyperlink

        public void hyperlink​(int r,
                              int c,
                              HyperLink hyperLink)
      • formula

        public void formula​(int r,
                            int c,
                            String expression)
        Set the cell formula at the given coordinates.
        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        expression - Cell formula expression.
      • inlineString

        public void inlineString​(int r,
                                 int c,
                                 String value)
        Set the cell value at the given coordinates.
        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        value - Cell value.
      • style

        public StyleSetter style​(int r,
                                 int c)
        Get a new style setter for a cell.
        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        Returns:
        Newly created style setter.
      • style

        public ColumnStyleSetter style​(int c)
        Get a new style setter for a column.
        Parameters:
        c - Zero-based column number.
        Returns:
        Newly created style setter.
      • range

        public Range range​(int top,
                           int left,
                           int bottom,
                           int right)
        Create a new range of cells. Note coordinates are reordered if necessary to make sure top <= bottom and left <= right.
        Parameters:
        top - Top row.
        left - Left column.
        bottom - Bottom row.
        right - Right column.
        Returns:
        Newly created range.
      • finish

        public void finish()
                    throws IOException
        Finish the construction of this worksheet. This creates the worksheet file on the workbook's output stream. Rows and cells in this worksheet are then destroyed.
        Throws:
        IOException - If an I/O error occurs.
      • flush

        public void flush()
                   throws IOException
        Write all the rows currently in memory to the workbook's output stream. Call this method periodically when working with huge data sets. After calling flush(), all the rows created so far become inaccessible.
        Notes:
        • All columns must be defined before calling this method: do not add or merge columns after calling flush().
        • When a Worksheet is flushed, no other worksheet can be flushed until close() (or the old fashion way finish()) is called.
        Throws:
        IOException - If an I/O error occurs.
      • comment

        public void comment​(int r,
                            int c,
                            String comment)
        Assign a note/comment to a cell. The comment popup will be twice the size of the cell and will be initially hidden.

        Comments are stored in memory till call to close() (or the old fashion way finish()) - calling flush() does not write them to output stream.

        Parameters:
        r - Zero-based row number.
        c - Zero-based column number.
        comment - Note text
      • hideGridLines

        public void hideGridLines()
        Hide grid lines.
      • rightToLeft

        public void rightToLeft()
        Display the worksheet from right to left
      • setZoom

        public void setZoom​(int zoomPercent)
        Set sheet view zoom level in percent. Default is 100 (100%).
        Parameters:
        zoomPercent - - zoom level from 10 to 400
      • setAutoPageBreaks

        public void setAutoPageBreaks​(Boolean autoPageBreaks)
      • setFitToPage

        public void setFitToPage​(Boolean fitToPage)
      • freezePane

        public void freezePane​(int nLeftColumns,
                               int nTopRows)
        Set freeze pane (rows and columns that remain when scrolling).
        Parameters:
        nLeftColumns - - number of columns from the left that will remain frozen
        nTopRows - - number of rows from the top that will remain frozen
      • unfreeze

        public void unfreeze()
        Unfreeze any frozen rows, or columns.
      • headerMargin

        public void headerMargin​(float margin)
        Set header margin.
        Parameters:
        margin - - header margin in inches
      • footerMargin

        public void footerMargin​(float margin)
        Set footer margin.
        Parameters:
        margin - - footer page margin in inches
      • topMargin

        public void topMargin​(float margin)
        Set top margin.
        Parameters:
        margin - - top page margin in inches
      • bottomMargin

        public void bottomMargin​(float margin)
        Set bottom margin.
        Parameters:
        margin - - bottom page margin in inches
      • leftMargin

        public void leftMargin​(float margin)
        Set left margin.
        Parameters:
        margin - - left page margin in inches
      • rightMargin

        public void rightMargin​(float margin)
        Set right margin.
        Parameters:
        margin - - right page margin in inches
      • pageOrientation

        public void pageOrientation​(String orientation)
        Set the page orientation.
        Parameters:
        orientation - New page orientation for this worksheet
      • paperSize

        public void paperSize​(PaperSize size)
        Set the paper size.
        Parameters:
        size - New paper size for this worksheet
      • pageScale

        public void pageScale​(int scale)
        Parameters:
        scale - = scaling factor for the print setup (between 1 and 100)
      • firstPageNumber

        public void firstPageNumber​(int pageNumber)
        Parameters:
        pageNumber - - first page number (default: 0)
      • fitToHeight

        public void fitToHeight​(Short fitToHeight)
      • fitToWidth

        public void fitToWidth​(Short fitToWidth)
      • printInBlackAndWhite

        public void printInBlackAndWhite()
      • printInColor

        public void printInColor()
      • repeatRows

        public void repeatRows​(int startRow,
                               int endRow)
      • repeatRows

        public void repeatRows​(int row)
      • repeatCols

        public void repeatCols​(int startCol,
                               int endCol)
      • repeatCols

        public void repeatCols​(int col)
      • footer

        public void footer​(String text,
                           Position position)
        Set footer text.
        Parameters:
        text - - text input form or custom text
        position - - Position.LEFT/RIGHT/CENTER enum
      • footer

        public void footer​(String text,
                           Position position,
                           int fontSize)
        Set footer text with specified font size.
        Parameters:
        text - - text input form or custom text
        position - - Position.LEFT/RIGHT/CENTER enum
        fontSize - - integer describing font size
      • footer

        public void footer​(String text,
                           Position position,
                           String fontName,
                           int fontSize)
        Set footer text with specified font and size.
        Parameters:
        text - - text input form or custom text
        position - - Position.LEFT/RIGHT/CENTER enum
        fontName - - font name (e.g., "Arial")
        fontSize - - integer describing font size
      • header

        public void header​(String text,
                           Position position,
                           String fontName,
                           int fontSize)
        Set header text.
        Parameters:
        text - - text input form or custom text
        position - - Position.LEFT/RIGHT/CENTER enum
        fontName - - font name (e.g., "Arial")
        fontSize - - integer describing font size
      • header

        public void header​(String text,
                           Position position,
                           int fontSize)
        Set header text with specified font size.
        Parameters:
        text - - text input form or custom text
        position - - Position.LEFT/RIGHT/CENTER enum
        fontSize - - integer describing font size
      • header

        public void header​(String text,
                           Position position)
        Set header text with specified font and size.
        Parameters:
        text - - text input form or custom text
        position - - Position.LEFT/RIGHT/CENTER enum
      • addNamedRange

        public void addNamedRange​(Range range,
                                  String name)
        Add the given range to this sheet's list of named ranges under the provided name. It will be visible when this sheet is open in the cell range dropdown menu under the specified name.
        Parameters:
        range - Range of cells that needs to be named.
        name - String representing the given cell range's name.
      • groupCols

        public void groupCols​(int from,
                              int to)
      • groupRows

        public void groupRows​(int from,
                              int to)
      • rowSumsBelow

        public void rowSumsBelow​(boolean rowSumsBelow)
      • rowSumsRight

        public void rowSumsRight​(boolean rowSumsRight)
      • setTabColor

        public void setTabColor​(String rgbColor)
        Parameters:
        rgbColor - FFF381E0