Class RangeImpl

java.lang.Object
io.keikai.api.impl.RangeImpl
All Implemented Interfaces:
Range, Serializable

public class RangeImpl extends Object implements Range, Serializable
1.Range does not handle the protection issue. By calling isSheetProtected() and getSheetProtection(), you can handle it easily.
Since:
3.0.0
Author:
dennis
See Also:
  • Constructor Details

    • RangeImpl

      public RangeImpl(SRange range, Sheet sheet)
    • RangeImpl

      public RangeImpl(SRange range, Book book)
  • Method Details

    • getLock

      public ReadWriteLock getLock()
      Specified by:
      getLock in interface Range
    • getCellStyleHelper

      public Range.CellStyleHelper getCellStyleHelper()
      Description copied from interface: Range
      Gets cell-style-helper, this helper helps you to create new style, font or color
      Specified by:
      getCellStyleHelper in interface Range
      Returns:
    • getCellData

      public CellData getCellData()
      Description copied from interface: Range
      Gets the first cell(top-left) data of this range
      Specified by:
      getCellData in interface Range
      Returns:
    • getNative

      public SRange getNative()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • isProtected

      public boolean isProtected()
      Specified by:
      isProtected in interface Range
      Returns:
      true if the specified range is protected; i.e. sheet is protected and some cells in the range are locked
    • isSheetProtected

      public boolean isSheetProtected()
      Specified by:
      isSheetProtected in interface Range
      Returns:
      true if the sheet is protected
    • isAnyCellProtected

      public boolean isAnyCellProtected()
    • paste

      public Range paste(Range dest, boolean cut)
      Description copied from interface: Range
      Cut and paste to destination. Support pasting cells among 2 books.
      Specified by:
      paste in interface Range
    • paste

      public Range paste(Range dest)
      Description copied from interface: Range
      Pastes to destination. Support pasting cells among 2 books.
      Specified by:
      paste in interface Range
      Parameters:
      dest - the destination. It can be a range of a different book.
      Returns:
      a Range contains the final pasted range. paste to a protected sheet will always cause paste return null.
    • pasteSpecial

      public Range pasteSpecial(Range dest, Range.PasteType type, Range.PasteOperation op, boolean skipBlanks, boolean transpose)
      Description copied from interface: Range
      Pastes to destination. Support pasting cells among 2 books.
      Specified by:
      pasteSpecial in interface Range
      Parameters:
      dest - the destination. It can be a range of a different book.
      type - the paste type
      op - the paste operation
      skipBlanks - skip blanks or not
      transpose - transpose the cell or not
      Returns:
      a Range contains the final pasted range. paste to a protected sheet will always cause paste return null.
    • clearContents

      public void clearContents()
      Description copied from interface: Range
      Clears contents
      Specified by:
      clearContents in interface Range
    • clearAll

      public void clearAll()
      Description copied from interface: Range
      Clears contents, styles and unmerge this range.
      Specified by:
      clearAll in interface Range
    • getSheet

      public Sheet getSheet()
      Description copied from interface: Range
      Gets the sheet of this range
      Specified by:
      getSheet in interface Range
      Returns:
      sheet
    • clearStyles

      public void clearStyles()
      Description copied from interface: Range
      Clears styles
      Specified by:
      clearStyles in interface Range
    • setCellStyle

      public void setCellStyle(CellStyle nstyle)
      Description copied from interface: Range
      Sets cell style, applies it to all cells of this range
      Specified by:
      setCellStyle in interface Range
      Parameters:
      nstyle - new cell style
      See Also:
    • getColumn

      public int getColumn()
      Description copied from interface: Range
      Gets the left column of this range
      Specified by:
      getColumn in interface Range
      Returns:
      the left column
    • getRow

      public int getRow()
      Description copied from interface: Range
      Gets the top row of this range
      Specified by:
      getRow in interface Range
      Returns:
      the top row
    • getLastColumn

      public int getLastColumn()
      Description copied from interface: Range
      Gets the right/last column of this range
      Specified by:
      getLastColumn in interface Range
      Returns:
    • getLastRow

      public int getLastRow()
      Description copied from interface: Range
      Gets the bottom/last row of this range
      Specified by:
      getLastRow in interface Range
      Returns:
    • sync

      public void sync(RangeRunner run)
      Description copied from interface: Range
      Runs runer under synchronization protection
      Specified by:
      sync in interface Range
      Parameters:
      run - the runner
    • visit

      public void visit(CellVisitor visitor)
      visit all cells in this range, make sure you call this in a limited range, don't use it for all row/column selection, it will spend much time to iterate the cell
      Specified by:
      visit in interface Range
      Parameters:
      visitor - the visitor
    • getBook

      public Book getBook()
      Description copied from interface: Range
      Gets the book of this range
      Specified by:
      getBook in interface Range
      Returns:
      book
    • applyBordersAround

      public void applyBordersAround(CellStyle.BorderType borderType, String htmlColor)
    • applyBorders

      public void applyBorders(Range.ApplyBorderType type, CellStyle.BorderType borderType, String htmlColor)
      Description copied from interface: Range
      apply borders
      Specified by:
      applyBorders in interface Range
      Parameters:
      type - the apply type
      borderType - the border type
      htmlColor - the color (#rgb-hex-code, e.x #FF00FF)
    • hasMergedCell

      public boolean hasMergedCell()
      Specified by:
      hasMergedCell in interface Range
      Returns:
      true if any merged cell inside (fully contains or overlaps) this range
    • isMergedCell

      public boolean isMergedCell()
      Specified by:
      isMergedCell in interface Range
      Returns:
      true if entire range is a merged cell.
    • getMergedRegion

      public CellRegion getMergedRegion()
      Description copied from interface: Range
      Returns the merged region of the left top cell of this Range if any; otherwise, returns null if not a merged region.
      Specified by:
      getMergedRegion in interface Range
      Returns:
      the merged region of the left top cell of this Range if any
    • getDataRegion

      public CellRegion getDataRegion()
      Description copied from interface: Range
      Returns the region which contains data(including chart, picture, and fills) in the sheet of this Range; return null if empty sheet.
      Specified by:
      getDataRegion in interface Range
      Returns:
      the region which contains data(including chart, picture, and fills) in the sheet of this Range; return null if empty sheet.
    • merge

      public void merge(boolean across)
      Description copied from interface: Range
      Merges the range
      Specified by:
      merge in interface Range
      Parameters:
      across - true if merge horizontally only
    • unmerge

      public void unmerge()
      Description copied from interface: Range
      Unmerge the range
      Specified by:
      unmerge in interface Range
    • toShiftedRange

      public RangeImpl toShiftedRange(int rowOffset, int colOffset)
      Description copied from interface: Range
      Return a new range by shifting the current Range according to the offsets but still keep the original height and width e.g.
       
       // range is A1:B2
       range.toShiftedRange(1, 0); //returns A2:B3
       
       
      Specified by:
      toShiftedRange in interface Range
      Parameters:
      rowOffset - row offset of the new range. Positive number shifts it down, negative number shifts it up.
      colOffset - column offset of the new range. Positive number shifts it right, negative number shifts it left.
      Returns:
      the new shifted range
    • toCellRange

      public RangeImpl toCellRange(int rowOffset, int colOffset)
      Description copied from interface: Range
      Returns a new range having one cell according to the offset based on the left-top corner. For example:
       
       //range is A1:B2
       range.toCellRange(0, 0); // returns A1
       
       
      Specified by:
      toCellRange in interface Range
      Parameters:
      rowOffset - row offset of the cell.
      colOffset - column offset of the cell.
      Returns:
      the new range of the cell
    • getLeftTop

      public RangeImpl getLeftTop()
      get the top-left cell range of this range
    • toRowRange

      public RangeImpl toRowRange()
      Return a range that represents all columns and between the first-row and last-row of this range
      Specified by:
      toRowRange in interface Range
    • toColumnRange

      public RangeImpl toColumnRange()
      Return a range that represents all rows and between the first-column and last-column of this range
      Specified by:
      toColumnRange in interface Range
    • isWholeColumn

      public boolean isWholeColumn()
      Check if this range represents a whole column, which mean all rows are included,
      Specified by:
      isWholeColumn in interface Range
    • isWholeRow

      public boolean isWholeRow()
      Check if this range represents a whole row, which mean all column are included,
      Specified by:
      isWholeRow in interface Range
    • isWholeSheet

      public boolean isWholeSheet()
      Check if this range represents a whole sheet, which mean all column and row are included,
      Specified by:
      isWholeSheet in interface Range
    • insert

      public void insert(Range.InsertShift shift, Range.InsertCopyOrigin copyOrigin)
      Description copied from interface: Range
      Insert new cells to the area of this range.
      To insert a row, you have to call Range.toRowRange() first, to insert a column, you have to call Range.toColumnRange() first.
      Specified by:
      insert in interface Range
      Parameters:
      shift - the shift direction of original cells
      copyOrigin - copy the format from nearby cells when inserting new cells
    • delete

      public void delete(Range.DeleteShift shift)
      Description copied from interface: Range
      Delete cells of the range.
      To delete a row, you have to call Range.toRowRange() first, to delete a column, you have to call Range.toColumnRange() first.
      Specified by:
      delete in interface Range
      Parameters:
      shift - the shift direction when deleting.
    • sort

      public void sort(boolean desc)
      Description copied from interface: Range
      Sort range
      Specified by:
      sort in interface Range
      Parameters:
      desc - true for descent, false for ascent
    • sort

      public void sort(boolean desc, boolean hasHeader, boolean matchCase, boolean sortByRows, Range.SortDataOption dataOption)
      Description copied from interface: Range
      Sort range
      Specified by:
      sort in interface Range
      Parameters:
      desc - true for descent, false for ascent
      hasHeader - includes header or not
      matchCase - matches character chase of not
      sortByRows - sorts by row or not
      dataOption - data option for sort
    • sort

      public void sort(Range key1, boolean desc1, Range.SortDataOption dataOption1, Range key2, boolean desc2, Range.SortDataOption dataOption2, Range key3, boolean desc3, Range.SortDataOption dataOption3, boolean header, boolean matchCase, boolean sortByRows)
      Description copied from interface: Range
      Sort range
      Specified by:
      sort in interface Range
      Parameters:
      key1 - the sort index 1
      desc1 - true for descent, false for ascent of index 1
      dataOption1 - data option 1 for sort
      key2 - the sort index 2
      desc2 - true for descent, false for ascent of index 2
      dataOption2 - data option 2 for sort
      key3 - the sort index 3
      desc3 - true for descent, false for ascent of index 3
      dataOption3 - data option31 for sort
      header - includes header or not
      matchCase - matches character chase of not
      sortByRows - sorts by row or not
    • isAutoFilterEnabled

      public boolean isAutoFilterEnabled()
      check if auto filter is enable or not.
      Specified by:
      isAutoFilterEnabled in interface Range
      Returns:
      true if auto filter is enabled.
    • findAutoFilterRange

      public Range findAutoFilterRange()
      Description copied from interface: Range
      To find a range of cells for applying auto filter according to this range. Usually, these two ranges are different. This method searches the filtering range through a specific rules.
      Specified by:
      findAutoFilterRange in interface Range
      Returns:
      a range of cells for applying auto filter or null if can't find one from this Range.
    • enableAutoFilter

      public void enableAutoFilter(boolean enable)
      enable/disable autofilter of the sheet
      Specified by:
      enableAutoFilter in interface Range
      Parameters:
      enable - true to enable
    • enableAutoFilter

      public void enableAutoFilter(int field, Range.AutoFilterOperation filterOp, Object criteria1, Object criteria2, Boolean showButton)
      enable filter with condition
      Specified by:
      enableAutoFilter in interface Range
      Parameters:
      field - the filed index (according to current range, 1 base)
      filterOp - auto filter operation
      criteria1 - criteria for autofilter
      criteria2 - criteria for autofilter
      showButton - true/false for show/hide dropdown button, null will keep the original setting.
    • resetAutoFilter

      public void resetAutoFilter()
      clear criteria of all filters, show all the data
      Specified by:
      resetAutoFilter in interface Range
    • applyAutoFilter

      public void applyAutoFilter()
      re-apply existing criteria of filters
      Specified by:
      applyAutoFilter in interface Range
    • autoFill

      public void autoFill(Range dest, Range.AutoFillType fillType)
      Description copied from interface: Range
      According to current range, fills data to destination range automatically
      Specified by:
      autoFill in interface Range
      Parameters:
      dest - the destination range
      fillType - the fill type
    • fillDown

      public void fillDown()
      Description copied from interface: Range
      Fills cells by copying from first/top row data
      Specified by:
      fillDown in interface Range
    • fillLeft

      public void fillLeft()
      Description copied from interface: Range
      Fills cells by copying from last/right column data
      Specified by:
      fillLeft in interface Range
    • fillUp

      public void fillUp()
      Description copied from interface: Range
      Fills cells by copying from bottom row data
      Specified by:
      fillUp in interface Range
    • fillRight

      public void fillRight()
      Description copied from interface: Range
      Fills cells by copying from first/left column data
      Specified by:
      fillRight in interface Range
    • shift

      public void shift(int rowOffset, int colOffset)
      shift this range with a offset row and column
      Specified by:
      shift in interface Range
    • getCellEditText

      public String getCellEditText()
      Description copied from interface: Range
      Gets the first cell(top-left) edit text of this range
      Specified by:
      getCellEditText in interface Range
      Returns:
      edit text
      See Also:
    • setCellEditText

      public void setCellEditText(String editText)
      Description copied from interface: Range
      Works like a user entering a text in a cell via a browser. So, this method supports "Smart Input", and it will parse the text and turn the text into a String, Number, Date, or Boolean according to the supported input format pattern. To enter a formula, the text should stat with =.
      This method applies all cells of this range.
      Specified by:
      setCellEditText in interface Range
      Parameters:
      editText - the text to enter, it can be a string, integer string, date string or a formula (start with '=')
    • setArrayFormula

      public void setArrayFormula(String editText)
      Description copied from interface: Range
      Works like a user entering an array formula in a cell or a range via a browser. So, this method supports "Smart Input", and it will parse the text and turn the text into a String, Number, Date, or Boolean according to the supported input format pattern. To enter a formula, the text should stat with =.
      This method applies all cells of this range.
      Specified by:
      setArrayFormula in interface Range
      Parameters:
      editText - the text to enter, it can be a string, integer string, date string or a formula (start with '=')
    • getCellFormatText

      public String getCellFormatText()
      Description copied from interface: Range
      Gets the first cell(top-left) formatted text of this range
      Specified by:
      getCellFormatText in interface Range
      Returns:
      format text
      See Also:
    • getCellDataFormat

      public String getCellDataFormat()
      Description copied from interface: Range
      Gets the first cell(top-left) format of this range
      Specified by:
      getCellDataFormat in interface Range
      Returns:
    • getCellValue

      public Object getCellValue()
      Description copied from interface: Range
      Gets the first cell(top-left) value of this range
      Specified by:
      getCellValue in interface Range
      Returns:
      value object or null for a blank cell
      See Also:
    • getCellValues

      public List<Object> getCellValues()
      Description copied from interface: Range
      Gets all cell values from left to right and top to bottom of this range in one dimensional list. Blank cell will be null value instead.
      If the range is A1:C3, the method will return you a list of cell values like:
      A1, B1, C1, A2, B2, C2, A3, B3, C3
      Specified by:
      getCellValues in interface Range
      Returns:
      values a object list
    • setDisplaySheetGridlines

      public void setDisplaySheetGridlines(boolean enable)
      Description copied from interface: Range
      Displays sheet grid-lines or not
      Specified by:
      setDisplaySheetGridlines in interface Range
      Parameters:
      enable - true to display
    • isDisplaySheetGridlines

      public boolean isDisplaySheetGridlines()
      Specified by:
      isDisplaySheetGridlines in interface Range
      Returns:
      true if display sheet grid-lines is enabled
    • setHidden

      public void setHidden(boolean hidden)
      Description copied from interface: Range
      Hide or unhide rows or columns.
      To hide/unhide a row, you have to call Range.toRowRange() first, to hide/un-hide a column, you have to call Range.toColumnRange() or a whole column range.
      Specified by:
      setHidden in interface Range
      Parameters:
      hidden - hide or not
    • setCellHyperlink

      public void setCellHyperlink(Hyperlink.HyperlinkType type, String address, String display)
      Description copied from interface: Range
      Sets cell hyperlink, applies it too all cells
      Specified by:
      setCellHyperlink in interface Range
      Parameters:
      type - the hyperlink type
      address - the address, e.x http://www.zkoss.org
      display - the label to display
    • getCellHyperlink

      public Hyperlink getCellHyperlink()
      Description copied from interface: Range
      Gets the first cell(top-left) Hyperlink object of this range.
      Specified by:
      getCellHyperlink in interface Range
      Returns:
    • setSheetName

      public void setSheetName(String name)
      Description copied from interface: Range
      Sets the sheet name
      Specified by:
      setSheetName in interface Range
      Parameters:
      name - new sheet name, it must be not same as another sheet name in it's owner book.
    • getSheetName

      public String getSheetName()
      Description copied from interface: Range
      Gets the sheet name
      Specified by:
      getSheetName in interface Range
      Returns:
      sheet name
    • setSheetOrder

      public void setSheetOrder(int pos)
      Description copied from interface: Range
      Sets the sheet order
      Specified by:
      setSheetOrder in interface Range
      Parameters:
      pos - the position
    • getSheetOrder

      public int getSheetOrder()
      Description copied from interface: Range
      Gets the sheet order
      Specified by:
      getSheetOrder in interface Range
      Returns:
    • setCellValue

      public void setCellValue(Object value)
      Description copied from interface: Range
      Sets cell data value and type. Notice that it doesn't parse the specified String object. If you call: setCellValue("100") , it will produce a text cell instead of an integer, one hundred. If you need a number cell, you need to call setCellValue(100) . The same rule applies to Date and Boolean.
      This method applies all cells of this range.
      Specified by:
      setCellValue in interface Range
      Parameters:
      value - the cell value, could be null, String, Number, Date or Boolean
      See Also:
    • setCellValues

      public void setCellValues(Object... values)
      Description copied from interface: Range
      Sets cell data values, applies them to all cells from left to right and top to bottom consistently. For example:

      Set values in a row

      
       Range rA1C1 = Ranges.range("A1:C1");
       rA1C1.setCellValues(3,2,1);
       
      The result is [3,2,1] from A1 to C1

      Set values in a column

      
       Range rA1A3 = Ranges.range("A1:A3");
       rA1A3.setCellValues(1,2,3);
       
      The result is [1,2,3] from A1 to A3

      Set values in an area

      
       Range rA1C3 = Ranges.range("A1:C3");
       rA1C3.setCellValues(9, 8, 7, 6, 5, 4, 3,2,1);
       
      The result is [9, 8, 7, 6, 5, 4, 3, 2, 1] from A1, B1, C1, A2, ... to C3

      Cell and values count mismatch

      If you pass more values than cell number, then it just sets cells in this range, not over-fill.
      
       rA1C1.setCellValues(1, 2, 3, 4, 5);
       
      The result is [1,2,3] from A1 to C1.

      If you pass fewer values than cell number, then it just set cells according the number of values.
      
       rA1C1.setCellValues(1, 2);
       
      The result is [1,2] from A1 to B1.

      Transpose 2D Array when necessary

      Since this method sets cells row by row, if you have a 2D array that contains column by column data. Then you can transpose the array first and pass to the method.
      Specified by:
      setCellValues in interface Range
      Parameters:
      values - all cell values, could be null, String, Number, Date or Boolean
    • getCellStyle

      public CellStyle getCellStyle()
      get the first cell style of this range
      Specified by:
      getCellStyle in interface Range
      Returns:
      cell style if cell is exist, the check row style and column cell style if cell not found, if row and column style is not exist, then return default style of sheet
    • addPicture

      public Picture addPicture(SheetAnchor anchor, byte[] image, Picture.Format format)
      Description copied from interface: Range
      Adds picture to sheet
      Specified by:
      addPicture in interface Range
      Parameters:
      anchor - the anchor for picture
      image - the image binary array
      format - the image format
      Returns:
      the new added picture
    • deletePicture

      public void deletePicture(Picture picture)
      Description copied from interface: Range
      Deletes picture that in sheet
      Specified by:
      deletePicture in interface Range
    • movePicture

      public void movePicture(SheetAnchor anchor, Picture picture)
      Description copied from interface: Range
      Moves picture
      Specified by:
      movePicture in interface Range
      Parameters:
      anchor - the anchor to re-allocate
      picture - the picture to re-allocate
    • updatePicture

      public void updatePicture(Picture picture, SheetAnchor.AnchorType anchorType)
      Description copied from interface: Range
      Updates picture with anchor type
      Specified by:
      updatePicture in interface Range
    • addChart

      public Chart addChart(SheetAnchor anchor, Chart.Type type, Chart.Grouping grouping, Chart.LegendPosition pos)
      Description copied from interface: Range
      Adds chart to sheet
      Specified by:
      addChart in interface Range
      Parameters:
      anchor - the destination anchor of the chart
      type - the chart type
      grouping - the chart grouping
      pos - the legend position
      Returns:
      the new added chart
    • addChart

      public Chart addChart(String name, SheetAnchor anchor, Chart.Type type, Chart.Grouping grouping, Chart.LegendPosition pos)
      Description copied from interface: Range
      Adds chart to sheet
      Specified by:
      addChart in interface Range
      Parameters:
      name - the name of chart
      anchor - the destination anchor of the chart
      type - the chart type
      grouping - the chart grouping
      pos - the legend position
      Returns:
      the new added chart
    • deleteChart

      public void deleteChart(Chart chart)
      Description copied from interface: Range
      Deletes chart
      Specified by:
      deleteChart in interface Range
      Parameters:
      chart - the chart to delete
    • moveChart

      public void moveChart(SheetAnchor anchor, Chart chart)
      Description copied from interface: Range
      Moves chart to new location
      Specified by:
      moveChart in interface Range
      Parameters:
      anchor - the new location to move
      chart - the chart to move
    • updateChart

      public void updateChart(Chart chart)
      Description copied from interface: Range
      Notify the component that a chart has change, e.g. call it after chart data changes.
      Specified by:
      updateChart in interface Range
      Parameters:
      chart - the chart that contains change
    • updateChart

      public void updateChart(Chart chart, SheetAnchor.AnchorType anchorType)
      Description copied from interface: Range
      Notify the component that a chart has change, e.g. call it after chart data changes.
      Specified by:
      updateChart in interface Range
      Parameters:
      chart - the chart that contains change
    • createSheet

      public Sheet createSheet(String name)
      Description copied from interface: Range
      Creates a new sheet and appends it as the last sheet. To move the new sheet to the specific position, see Range.setSheetOrder(int).
      Specified by:
      createSheet in interface Range
      Parameters:
      name - the sheet name, it must not be same as another sheet name in book of this range. Otherwise, it takes no effect.
      Returns:
      the new created sheet
    • cloneSheet

      public Sheet cloneSheet(String name)
      Description copied from interface: Range
      Clone this sheet; create a sheet and copy the contents of this sheet; then add it as the last sheet.
      Specified by:
      cloneSheet in interface Range
      Parameters:
      name - the sheet name, it must not be the same as another sheet name in book of this range
      Returns:
      the new created sheet
    • deleteSheet

      public void deleteSheet()
      Description copied from interface: Range
      Deletes sheet. Note: You couldn't delete last sheet of a book.
      Specified by:
      deleteSheet in interface Range
    • setColumnWidth

      public void setColumnWidth(int widthPx)
      Description copied from interface: Range
      Sets the width (in pixels) of the columns in this range.

      Visibility effect:

      • If widthPx is 0, it hides the columns implicitly.
      • If widthPx is a positive value, it unhides the columns automatically.
      • It affects entire columns even if the range only contains some cells (implicitly calls Range.toColumnRange()).
      • The column width will be marked as custom and disables "best fit".
      • It may trigger re-refresh of cell contents (e.g., changing displayed number precision).
      Specified by:
      setColumnWidth in interface Range
      Parameters:
      widthPx - width in pixels. A value of 0 hides the columns, while a positive value unhides them and sets their width.
      See Also:
    • setRowHeight

      public void setRowHeight(int heightPx)
      Description copied from interface: Range
      Sets the height(in pixel) of row in this range, it effect to whole row.
      Specified by:
      setRowHeight in interface Range
      Parameters:
      heightPx - height in pixel
      See Also:
    • setRowHeight

      public void setRowHeight(int heightPx, boolean isCustom)
      Description copied from interface: Range
      Sets the height(in pixel) of row in this range and specify it's custom size or not.
      Specified by:
      setRowHeight in interface Range
      Parameters:
      heightPx - height in pixel
      isCustom - true if it's set by users manually, false if it's determined by the system automatically
    • group

      public void group()
      Description copied from interface: Range
      Groups the rows or columns by matching the range, which increases their outline level.

      Note: The maximum level is up to 7.

      Specified by:
      group in interface Range
    • ungroup

      public void ungroup()
      Description copied from interface: Range
      Ungroups the rows or columns by matching the range, which decreases their outline level.

      Note: The minimum level is down to 0.

      Specified by:
      ungroup in interface Range
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • notifyChange

      public void notifyChange()
      Description copied from interface: Range
      Notify this range has been changed, then spreadsheet will render the changed cells to a browser. It's usually used with Range.setAutoRefresh(boolean).
      Specified by:
      notifyChange in interface Range
    • notifyChange

      public void notifyChange(String[] variables)
      Description copied from interface: Range
      Notify the whole book of specified variables change. Then spreadsheet will re-evaluate those cells that reference to these variables.
      Specified by:
      notifyChange in interface Range
      Parameters:
      variables - changed variables
    • setFreezePanel

      public void setFreezePanel(int rowfreeze, int columnfreeze)
      Description copied from interface: Range
      Set the freeze panel
      Specified by:
      setFreezePanel in interface Range
      Parameters:
      rowfreeze - the number of row to freeze, 0 means no freeze
      columnfreeze - the number of column to freeze, 0 means no freeze
    • getRowCount

      public int getRowCount()
      Description copied from interface: Range
      Gets the row count of this range
      Specified by:
      getRowCount in interface Range
      Returns:
      count of row of this range
    • getColumnCount

      public int getColumnCount()
      Description copied from interface: Range
      Gets the column count of this range
      Specified by:
      getColumnCount in interface Range
      Returns:
      count of column of this range
    • asString

      public String asString()
      Description copied from interface: Range
      get formatted string of this range
      Specified by:
      asString in interface Range
      Returns:
    • getInternalRange

      public SRange getInternalRange()
      Description copied from interface: Range
      Get internal range implementation
      Specified by:
      getInternalRange in interface Range
    • createName

      public void createName(String nameName)
      Description copied from interface: Range
      Create a name that refers to this range. You can get this named ranage by Ranges.rangeByName(Sheet, String).
      Specified by:
      createName in interface Range
      Parameters:
      nameName - name of the range that you can refer in formulas.
    • protectSheet

      public void protectSheet(String password, boolean allowSelectingLockedCells, boolean allowSelectingUnlockedCells, boolean allowFormattingCells, boolean allowFormattingColumns, boolean allowFormattingRows, boolean allowInsertColumns, boolean allowInsertRows, boolean allowInsertingHyperlinks, boolean allowDeletingColumns, boolean allowDeletingRows, boolean allowSorting, boolean allowFiltering, boolean allowUsingPivotTables, boolean drawingObjects, boolean scenarios)
      Description copied from interface: Range
      Protect a Sheet so that it cannot be modified. You can call this method on a protected sheet to change its allowed options if the same password is supplied; otherwise, it is ignored. A protected sheet can be unprotected by calling Range.unprotectSheet(String password). change the protection options; make sure provide
      Specified by:
      protectSheet in interface Range
      Parameters:
      password - a case-sensitive password for the sheet; null or empty string means protect the sheet without password.
      allowSelectingLockedCells - true to allow select locked cells; default to true.
      allowSelectingUnlockedCells - true to allow select unlocked cells; default to true.
      allowFormattingCells - true to allow user to format any cell on the protected sheet; default false.
      allowFormattingColumns - true to allow user to format any columns on the protected sheet; default false.
      allowFormattingRows - true to allow user to format any rows on the protected sheet; default false.
      allowInsertColumns - true to allow user to insert columns on the protected sheet; default false.
      allowInsertRows - true to allow user to insert rows on the protected sheet; default false.
      allowInsertingHyperlinks - true to allow user to insert hyperlinks on the protected sheet; default false.
      allowDeletingColumns - true to allow user to delete columns on the protected sheet; default false.
      allowDeletingRows - true to allow user to delete rows on the protected sheet; default false.
      allowSorting - true to allow user to sort on the protected sheet; default false.
      allowFiltering - true to allow user to set filters on the protected sheet; default false.
      allowUsingPivotTables - true to allow user to use pivot table reports on the protected sheet; default false.
      drawingObjects - true to protect objects; default to false.
      scenarios - true to protect scenarios; default to true.
      See Also:
    • protectSheet

      public void protectSheet(SheetProtection protection)
      Description copied from interface: Range
      Protect a Sheet so that it cannot be modified.
      Specified by:
      protectSheet in interface Range
      See Also:
    • unprotectSheet

      public boolean unprotectSheet(String password)
      Description copied from interface: Range
      Removes protection from a sheet. This method has no effect if the sheet isn't protected.
      Specified by:
      unprotectSheet in interface Range
      Parameters:
      password - a case-sensitive password used to unprotect the sheet. If the sheet isn't protected with a password, this argument is ignored. If you omit this argument for a sheet that is protected with a password, you'll be prompted for the password.
    • getSheetProtection

      public SheetProtection getSheetProtection()
      Description copied from interface: Range
      Gets SheetProtection which tells what are allowed operations for a protected sheet of this range.
      Specified by:
      getSheetProtection in interface Range
      Returns:
    • validate

      public Validation validate(String editText)
      Description copied from interface: Range
      validate the user's input.
      Specified by:
      validate in interface Range
      Returns:
      the Validation that constraint the input; null if none.
    • setValidation

      public void setValidation(Validation.ValidationType validationType, boolean ignoreBlank, Validation.OperatorType operatorType, boolean inCellDropDown, String formula1, String formula2, boolean showInput, String inputTitle, String inputMessage, boolean showError, Validation.AlertStyle alertStyle, String errorTitle, String errorMessage)
      Description copied from interface: Range
      Add if not exist or modify an existing Validation to this range. There are two ways to input list items for data validation in argument "formula1" and "formula2". One is to specify a range via a formula such as "=A1:A4" where the values in the cells of the range is the constrained value list; another is to input literally the constrained value list delimited by comma such as "1, 2, 3, 4". Note that when you input a formula, must lead the formula with an equal sign('=').
      Specified by:
      setValidation in interface Range
      Parameters:
      validationType - the type of this validation
      ignoreBlank - true if blank values are permitted.
      operatorType - the operator for this validation
      inCellDropDown - true if want to display dropdown list for acceptable values.
      formula1 - the value or expression associated with conditional format or data validation.
      formula2 - the 2nd part of a conditional format or data validation. Useful only when operatorType is BETWEEN or NOT_BETWEEN.
      showInput - true to show the input message.
      inputTitle - title for the data-validation input dialog box.
      inputMessage - message for the data-validation input dialog box.
      showError - true to show the error message.
      alertStyle - validation alert style.
      errorTitle - title of the data validation error dialog.
      errorMessage - data validation error message.
    • getValidations

      public List<Validation> getValidations()
      Description copied from interface: Range
      Gets read-only Validation associated with the left-top cell of this range; return null if no associated validation.
      Specified by:
      getValidations in interface Range
      See Also:
    • deleteValidation

      public void deleteValidation()
      Description copied from interface: Range
      Delete the Validation associated in the specified range.
      Specified by:
      deleteValidation in interface Range
    • setCellRichText

      public void setCellRichText(String html)
      Description copied from interface: Range
      Set into the left top cell of this Range the specified text in html format.
      Specified by:
      setCellRichText in interface Range
    • getCellRichText

      public String getCellRichText()
      Description copied from interface: Range
      Returns text in html format; null if not a rich text.
      Specified by:
      getCellRichText in interface Range
    • getOrCreateFont

      public Font getOrCreateFont(Font.Boldweight boldweight, Color color, int fontHeight, String fontName, boolean italic, boolean strikeout, Font.TypeOffset typeOffset, Font.Underline underline)
      Description copied from interface: Range
      Get font if exists or create font if not exists from the book of this range and return it.
      Specified by:
      getOrCreateFont in interface Range
      Returns:
      font of the specified font metrics
    • refresh

      public void refresh(boolean includeDependants)
      Description copied from interface: Range
      Enforce evaluation(if not cached) and refresh UI of this range and its dependent cells if the includeDependents is true. This method is equal to {@link Range#refresh(boolean includeDependents, boolean false, boolean true)}.
      Specified by:
      refresh in interface Range
    • setAutoRefresh

      public boolean setAutoRefresh(boolean auto)
      Description copied from interface: Range
      Turn on(true)/off(false) of auto refresh of this range and return previous on/off status; default is true. If you turn off auto refresh, you need to call Range.notifyChange() manually at the proper moment.
      Specified by:
      setAutoRefresh in interface Range
      Parameters:
      auto - whether refresh automatically
      Returns:
      previous status
    • refresh

      public void refresh(boolean includeDependants, boolean clearCache, boolean enforceEval)
      Description copied from interface: Range
      Update data model and refresh UI of this range and its dependent cells if the argument includeDependents is true. Note that when you set parameter clearCache to true, the cached formula result in data model will be cleared first. If you set parameter enforceEval to true, data model associated with this range will be evaluated immediately; otherwise will be evaluated on demand.
      Specified by:
      refresh in interface Range
    • setSheetVisible

      public void setSheetVisible(Range.SheetVisible visible)
      Description copied from interface: Range
      Setup sheet's visibility; can be VISIBLE, HIDDEN, or VERY_HIDDEN.
      • VISIBLE: the sheet is visible
      • HIDDEN: the sheet is hidden but can be unhidden using UI
      • VERY_HIDDEN: the sheet is hidden but can be unhidden only via this API.
      Specified by:
      setSheetVisible in interface Range
      See Also:
    • getCommentRichText

      public String getCommentRichText()
      Description copied from interface: Range
      Return the comment rich edit text of the left top cell of this Range.
      Specified by:
      getCommentRichText in interface Range
      Returns:
      the rich edit text of this Range.
    • setCommentRichText

      public void setCommentRichText(String html)
      Description copied from interface: Range
      Set comment rich text into the left top cell of this range; null to delete it.
      Specified by:
      setCommentRichText in interface Range
    • setCommentVisible

      public void setCommentVisible(boolean visible)
      Description copied from interface: Range
      Set comment visibility into the left top cell of this range; if no comment at the cell, it simply ignored.
      Specified by:
      setCommentVisible in interface Range
    • isCommentVisible

      public boolean isCommentVisible()
      Description copied from interface: Range
      Returns whether the comment is always visible at the left top cell of this range; if no comment at the cell, it returns false.
      Specified by:
      isCommentVisible in interface Range
      Returns:
    • notifyChange

      public void notifyChange(Range.CellAttribute cellAttr)
      Description copied from interface: Range
      Notify this range has been changed on the specifield attribute.
      Specified by:
      notifyChange in interface Range
    • setNameName

      public void setNameName(String namename, String newname)
      Description copied from interface: Range
      Set(Rename) the name of the Name(or Table) as specified in this Range(a Book or a Sheet).
      Specified by:
      setNameName in interface Range
      Parameters:
      namename - name of the Name(or Table)
      newname - new name for the Name(or Table)
    • setStringValue

      public void setStringValue(String text)
      Description copied from interface: Range
      Save the specified value into this range as a String no matter the value is prefixed with '=' or not.
      Specified by:
      setStringValue in interface Range
    • cloneSheetFrom

      public Sheet cloneSheetFrom(String name, Sheet sheet)
      Description copied from interface: Range
      Clone from the specified source sheet to the owner book of this range. The book can be different between the owner book of this range and of the specified source sheet.
      Specified by:
      cloneSheetFrom in interface Range
      Parameters:
      name - the name of the new created sheet; null would try to use the sheet name of the specified source sheet; if the same sheet name already used in the owner book of this range then use default "SheetX" name where X is the next sheet number of the owner book of this range.
      sheet - the source sheet to clone from to the owner book of this range.
      Returns:
      the new created sheet
      See Also:
    • cloneSheetFrom

      public Sheet cloneSheetFrom(String name, Sheet sheet, boolean valueOnly)
      Description copied from interface: Range
      Clone from the specified source sheet to the owner book of this range. The book can be different between the owner book of this range and of the specified source sheet.
      Specified by:
      cloneSheetFrom in interface Range
      Parameters:
      name - the name of the new created sheet; null would try to use the sheet name of the specified source sheet; if the same sheet name already used in the owner book of this range then use default "SheetX" name where X is the next sheet number of the owner book of this range.
      sheet - the source sheet to clone from to the owner book of this range.
      valueOnly - true to copy the cell value only
      Returns:
      the new created sheet
    • zOrderStream

      public Stream<Range> zOrderStream()
      Description copied from interface: Range
      Returns a z-order cell range stream which treats a merged cell as one range. For example,
      
          //  Data:
          //     | A | B | C | D | E |
          //  ---+---+---+---+---+---+
          //   1 | 1 |       | 3 |   |
          //  ---+---+       +---+---+
          //   2 |   |       |   |   |
          //  ---+   +       + 5 +---+
          //   3 | 4 |   2   |   |   |
          //  ---+   +       +---+---+
          //   4 |   |       | 6 |   |
          //  ---+---+       +---+---+
          //   5 | 7 |       | 8 |   |
          //  ---+---+-------+---+---+
      
          Stream zOrder = Ranges.range("A1:D5").zOrderStream();
                zOrder.map(Range::getCellValue)
                      .map(Object::toString)
                      .collect(Collectors.joining(", "));
                // Result: 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0
       
      Specified by:
      zOrderStream in interface Range
    • nOrderStream

      public Stream<Range> nOrderStream()
      Description copied from interface: Range
      Returns a n-order cell range stream which treats a merged cell as one range. For example,
      
           //  Data:
           //     | A | B | C | D | E |
           //  ---+---+---+---+---+---+
           //   1 | 1 |       | 3 |   |
           //  ---+---+       +---+---+
           //   2 |   |       |   |   |
           //  ---+   +       + 5 +---+
           //   3 | 4 |   2   |   |   |
           //  ---+   +       +---+---+
           //   4 |   |       | 6 |   |
           //  ---+---+       +---+---+
           //   5 | 7 |       | 8 |   |
           //  ---+---+-------+---+---+
      
          Stream nOrder = Ranges.range("A1:D5").nOrderStream();
                nOrder.map(Range::getCellValue)
                      .map(Object::toString)
                      .collect(Collectors.joining(", "));
      
                // Result: 1.0, 4.0, 7.0, 2.0, 3.0, 5.0, 6.0, 8.0
       
      Specified by:
      nOrderStream in interface Range
    • getDirectPrecedents

      public Set<Range> getDirectPrecedents()
      Description copied from interface: Range
      Returns Range(s) that are the direct precedents of this cell Range. If this Range covers more than one cell, the left-top one is used.
      Specified by:
      getDirectPrecedents in interface Range
    • getPrecedents

      public Set<Range> getPrecedents()
      Description copied from interface: Range
      Returns all Range(s) that are the direct or indirect precedents of this cell Range. If this Range covers more than one cell, the left-top one is used.
      Specified by:
      getPrecedents in interface Range
    • getDirectDependents

      public Set<Range> getDirectDependents()
      Description copied from interface: Range
      Returns Range(s) that are the direct dependents of this cell Range. If this Range covers more than one cell, the left-top one is used.
      Specified by:
      getDirectDependents in interface Range
    • getDependents

      public Set<Range> getDependents()
      Description copied from interface: Range
      Returns all Range(s) that are the direct or indirect dependents of this cell Range. If this Range covers more than one cell, the left-top one is used.
      Specified by:
      getDependents in interface Range
    • tracePrecedents

      public void tracePrecedents()
      Description copied from interface: Range
      Trace the precedents of this range.
      Specified by:
      tracePrecedents in interface Range
    • traceDependents

      public void traceDependents()
      Description copied from interface: Range
      Trace the dependents of this range.
      Specified by:
      traceDependents in interface Range
    • clearTrace

      public void clearTrace()
      Description copied from interface: Range
      Clears the current tracing.
      Specified by:
      clearTrace in interface Range
    • getRowGroups

      public List<Range> getRowGroups()
      Description copied from interface: Range
      Returns all group ranges for rows, which intersect with this range.
      Specified by:
      getRowGroups in interface Range
      Returns:
      an empty list if not matched.
    • getRowGroups

      public List<Range> getRowGroups(int outlineLevel)
      Description copied from interface: Range
      Returns all group ranges matched the given outline level for rows, which intersect with this range.
      Specified by:
      getRowGroups in interface Range
      Parameters:
      outlineLevel - a valid value in a range is from 1 to 7 (inclusive).
      Returns:
      an empty list if not matched.
    • getRowGroups

      public List<Range> getRowGroups(int fromOutlineLevel, int toOutlineLevel)
      Description copied from interface: Range
      Returns all group ranges matched between fromOutlineLevel and toOutlineLevel for rows, which intersect with this range.
      Specified by:
      getRowGroups in interface Range
      Parameters:
      fromOutlineLevel - 1~7 (inclusive)
      toOutlineLevel - 2~8 (exclusive)
      Returns:
      an empty list if not matched.
    • getColumnGroups

      public List<Range> getColumnGroups()
      Description copied from interface: Range
      Returns all group ranges for columns, which intersect with this range.
      Specified by:
      getColumnGroups in interface Range
      Returns:
      an empty list if not matched.
    • getColumnGroups

      public List<Range> getColumnGroups(int outlineLevel)
      Description copied from interface: Range
      Returns all group ranges matched the given outline level for columns, which intersect with this range.
      Specified by:
      getColumnGroups in interface Range
      Parameters:
      outlineLevel - a valid value in a range is from 1 to 7 (inclusive).
      Returns:
      an empty list if not matched.
    • getColumnGroups

      public List<Range> getColumnGroups(int fromOutlineLevel, int toOutlineLevel)
      Description copied from interface: Range
      Returns all group ranges matched between fromOutlineLevel and toOutlineLevel for columns, which intersect with this range.
      Specified by:
      getColumnGroups in interface Range
      Parameters:
      fromOutlineLevel - 1~7 (inclusive)
      toOutlineLevel - 2~8 (exclusive)
      Returns:
      an empty list if not matched.
    • setSummaryBelow

      public void setSummaryBelow(boolean summaryBelow)
      Description copied from interface: Range
      Sets to be true to display summary group as below or to be false to display summary group as above for rows.

      Note: One setting to affect whole sheet, if the value is up-side-down against the previous value, it will clear all outline level for rows and columns.

      Default: true

      Specified by:
      setSummaryBelow in interface Range
      Parameters:
      summaryBelow - true to display as below for rows.
    • isSummaryBelow

      public boolean isSummaryBelow()
      Description copied from interface: Range
      Returns whether to display group summary as below for rows.

      Default: true

      Specified by:
      isSummaryBelow in interface Range
    • setSummaryRight

      public void setSummaryRight(boolean summaryRight)
      Description copied from interface: Range
      Sets to be true to display summary group as right or to be false to display summary group as left for columns.

      Note: One setting to affect whole sheet, if the value is up-side-down against the previous value, it will clear all outline level for rows and columns.

      Default: true

      Specified by:
      setSummaryRight in interface Range
      Parameters:
      summaryRight - true to display as right for columns.
    • isSummaryRight

      public boolean isSummaryRight()
      Description copied from interface: Range
      Returns whether to display group summary as right for columns.

      Default: true

      Specified by:
      isSummaryRight in interface Range
    • collapse

      public void collapse()
      Description copied from interface: Range
      Collapses one group by matching with the range at a time (not affected its descendant).
      Specified by:
      collapse in interface Range
    • expand

      public void expand()
      Description copied from interface: Range
      Expands one group by matching with the range at a time (not affected its descendant).
      Specified by:
      expand in interface Range
    • clearOutlineLevel

      public void clearOutlineLevel()
      Description copied from interface: Range
      Clears all outline level for all groups that intersect with the range. 2:4 for rows and C:E for columns
      Specified by:
      clearOutlineLevel in interface Range
    • isCollapsed

      public boolean isCollapsed()
      Description copied from interface: Range
      Returns whether the group by matching with the range has collapsed or not. Otherwise, returns false instead.
      Specified by:
      isCollapsed in interface Range
    • getOutlineLevel

      public int getOutlineLevel()
      Description copied from interface: Range
      Returns the outline of the group by matching with the range. Otherwise, returns 0 instead.
      Specified by:
      getOutlineLevel in interface Range