Class SheetImpl

All Implemented Interfaces:
LinkedModelObject, SSheet, Serializable

public class SheetImpl extends AbstractSheetAdv
Since:
3.5.0
Author:
dennis
See Also:
  • Constructor Details

  • Method Details

    • checkOwnership

      protected void checkOwnership(SPicture picture)
    • checkOwnership

      protected void checkOwnership(SChart chart)
    • checkOwnership

      protected void checkOwnership(SDataValidation validation)
    • getBook

      public SBook getBook()
      Description copied from interface: SSheet
      Get the owner book
      Returns:
      the owner book
    • getSheetName

      public String getSheetName()
      Description copied from interface: SSheet
      Get the sheet name
      Returns:
      the sheet name
    • getRow

      public SRow getRow(int rowIdx)
    • getColumn

      public SColumn getColumn(int columnIdx)
    • getColumnArray

      public SColumnArray getColumnArray(int columnIdx)
      See Also:
    • setupColumnArray

      public SColumnArray setupColumnArray(int index, int lastIndex)
      Description copied from interface: SSheet
      Set up a column array, if one array range overlaps another, it throws IllegalStateException. If you setup a column array that is not continuous, (for example, 0~2, 5~6), then it will create a missing column array automatically to make them continuous.(3~4 in the example). It's required to set up in ascending order of starting column index (min), or it will create unexpected SColumnArray for columns are not continuous.
      Parameters:
      index - index of the starting column
      lastIndex - index of the end column
      Returns:
      the new created column array
    • getCell

      public SCell getCell(int rowIdx, int columnIdx)
      Description copied from interface: SSheet
      This method always returns not-null cell object. Use SCell.isNull() to know it's null (blank) or not.
    • getCell

      public SCell getCell(String cellRef)
      Returns:
      return a cell with specified cell reference, e.g. A2, B3. Area reference, A1:A2, is not acceptable.
      See Also:
    • getStartRowIndex

      public int getStartRowIndex()
    • getEndRowIndex

      public int getEndRowIndex()
    • getStartColumnIndex

      public int getStartColumnIndex()
    • getEndColumnIndex

      public int getEndColumnIndex()
    • getStartCellIndex

      public int getStartCellIndex(int rowIdx)
    • getEndCellIndex

      public int getEndCellIndex(int rowIdx)
    • clearCell

      public void clearCell(CellRegion region)
      Description copied from interface: SSheet
      Clear cells in specified region
    • clearCell

      public void clearCell(int rowIdx, int columnIdx, int rowIdx2, int columnIdx2)
      See Also:
    • insertRow

      public void insertRow(int rowIdx, int lastRowIdx)
      Description copied from interface: SSheet
      insert rows specified by first and last index
    • deleteRow

      public void deleteRow(int rowIdx, int lastRowIdx)
      Description copied from interface: SSheet
      delete rows specified by first and last index
    • insertCell

      public void insertCell(CellRegion region, boolean horizontal)
      Description copied from interface: SSheet
      Insert a region of cells and shift existing cells.
      Parameters:
      region - the region of cells to insert
      horizontal - TRUE for shifting right, FALSE for shifting down
    • insertCell

      public void insertCell(int rowIdx, int columnIdx, int lastRowIdx, int lastColumnIdx, boolean horizontal)
      See Also:
    • deleteCell

      public void deleteCell(CellRegion region, boolean horizontal)
      Description copied from interface: SSheet
      Delete a region of cells and shift existing cells.
      Parameters:
      region - the region of cells to delete
      horizontal - TRUE for shifting left, FALSE for shifting up
    • deleteCell

      public void deleteCell(int rowIdx, int columnIdx, int lastRowIdx, int lastColumnIdx, boolean horizontal)
      See Also:
    • dump

      public void dump(StringBuilder builder)
    • insertColumn

      public void insertColumn(int columnIdx, int lastColumnIdx)
      Description copied from interface: SSheet
      insert columns specified by first and last index
    • deleteColumn

      public void deleteColumn(int columnIdx, int lastColumnIdx)
      Description copied from interface: SSheet
      delete columns specified by first and last index
    • moveCell

      public void moveCell(CellRegion region, int rowOffset, int columnOffset)
      Description copied from interface: SSheet
      Move one or more cells.
      Parameters:
      region - the region of cells to move
      rowOffset - positive number to move down, negative to move up
      columnOffset - positive number to move right, negative to move left
    • moveCell

      public void moveCell(int rowIdx, int columnIdx, int lastRowIdx, int lastColumnIdx, int rowOffset, int columnOffset)
      Description copied from interface: SSheet
      Move a region of cells specified by 4 indexes.
      See Also:
    • checkOrphan

      public void checkOrphan()
    • destroy

      public void destroy()
      Description copied from interface: LinkedModelObject
      Destroy / release this model object, for example all the dependency, parent linking. this method has to be called before remove this linking from parent object
    • getId

      public String getId()
      Returns:
      interal sheet object ID
    • addPicture

      public SPicture addPicture(SPicture.Format format, byte[] data, ViewAnchor anchor)
      Description copied from interface: SSheet
      Add a picture into this sheet with raw picture data and format.
      Parameters:
      format - picture format as specified in SPicture.Format
      data - raw byte data of the picture
      anchor - where to anchor this picture
      Returns:
      the added SPicture
    • addPicture

      public SPicture addPicture(int picDataIndex, ViewAnchor anchor)
      Description copied from interface: SSheet
      Add a picture into the sheet with known picture data index.
      Parameters:
      picDataIndex - SPictureData index
      anchor - where to anchor this picture
      Returns:
      the SPicture added
    • getPicture

      public SPicture getPicture(String picid)
    • deletePicture

      public void deletePicture(SPicture picture)
    • getPictures

      public List<SPicture> getPictures()
    • getNumOfPicture

      public int getNumOfPicture()
    • getPicture

      public SPicture getPicture(int idx)
    • addChart

      public SChart addChart(SChart.ChartType type, ViewAnchor anchor)
    • addChart

      public SChart addChart(String name, SChart.ChartType type, ViewAnchor anchor)
      Description copied from interface: SSheet
      Add a chart with name, type and anchor
      Returns:
      the created chart
    • getChartByName

      public SChart getChartByName(String name)
      Description copied from interface: SSheet
      Returns the first chart with specific name
      Returns:
      the chart with specific name
    • getChartsByName

      public List<SChart> getChartsByName(String name)
      Description copied from interface: SSheet
      Returns the charts with specific name
      Returns:
      the charts with specific name
    • getChart

      public SChart getChart(String picid)
    • deleteChart

      public void deleteChart(SChart chart)
    • getCharts

      public List<SChart> getCharts()
    • getNumOfChart

      public int getNumOfChart()
    • getChart

      public SChart getChart(int idx)
    • getMergedRegions

      public List<CellRegion> getMergedRegions()
    • removeMergedRegion

      public void removeMergedRegion(CellRegion region, boolean removeOverlaps)
      Description copied from interface: SSheet
      Remove the merged area that are contained by region
      removeOverlaps - true if you want to remove the merged areas that are just overlapped.
    • addMergedRegion

      public void addMergedRegion(CellRegion region)
      Description copied from interface: SSheet
      Add a merged area, you can't assign a area that overlaps existed merged area.
    • getOverlapsMergedRegions

      public List<CellRegion> getOverlapsMergedRegions(CellRegion region, boolean excludeContains)
      Description copied from interface: SSheet
      Get the merged region that overlapped the region
      Returns:
      the regions that overlaps
    • getContainsMergedRegions

      public List<CellRegion> getContainsMergedRegions(CellRegion region)
      Description copied from interface: SSheet
      Get the merged region that are contained by region.
      Returns:
      the regions that are contained
    • getMergedRegion

      public CellRegion getMergedRegion(String cellRef)
    • getMergedRegion

      public CellRegion getMergedRegion(int row, int column)
    • getAttribute

      public Object getAttribute(String name)
      Description copied from interface: SSheet
      Get the runtime custom attribute that stored in this sheet
      Parameters:
      name - the attribute name
      Returns:
      the value, or null if not found
    • setAttribute

      public Object setAttribute(String name, Object value)
      Description copied from interface: SSheet
      Set the runtime custom attribute to stored in this sheet, the attribute is only use for developer to stored runtime data in the sheet, values will not stored to excel when exporting.
      Parameters:
      name - name the attribute name
      value - the attribute value
    • getAttributes

      public Map<String,Object> getAttributes()
      Description copied from interface: SSheet
      Get the unmodifiable runtime attributes map
      Returns:
    • getRowIterator

      public Iterator<SRow> getRowIterator()
      Returns:
      an iterator of existing rows excluding those blank rows
    • getRowIterator

      public Iterator<SRow> getRowIterator(int start, int end)
      Parameters:
      start - the start index
      end - the end index
      Returns:
      an iterator of existing rows excluding those blank rows
    • getRowIterator

      public Iterator<AbstractRowAdv> getRowIterator(boolean reverse, int start, int end)
      Specified by:
      getRowIterator in class AbstractSheetAdv
    • getColumnArrayIterator

      public Iterator<SColumnArray> getColumnArrayIterator()
    • getColumnIterator

      public Iterator<SColumn> getColumnIterator()
      Returns:
      an iterator of existing columns excluding those blank columns
    • getCellIterator

      public Iterator<SCell> getCellIterator(int row)
    • getDefaultRowHeight

      public int getDefaultRowHeight()
      Returns:
      default row height in pixels
    • getDefaultColumnWidth

      public int getDefaultColumnWidth()
      Returns:
      default column width in pixels
    • setDefaultRowHeight

      public void setDefaultRowHeight(int height)
      Description copied from interface: SSheet
      set default row height in pixels
    • setDefaultColumnWidth

      public void setDefaultColumnWidth(int width)
      Description copied from interface: SSheet
      set default column width in pixels
    • getNumOfMergedRegion

      public int getNumOfMergedRegion()
    • getMergedRegion

      public CellRegion getMergedRegion(int idx)
    • isProtected

      public boolean isProtected()
      Description copied from interface: SSheet
      Check if the sheet is protected
      Returns:
    • setTabColor

      public void setTabColor(String tabColor)
      Description copied from interface: SSheet
      Set sheet tab color
    • getTabColor

      public String getTabColor()
      Returns:
      sheet tab color
    • setPassword

      public void setPassword(String password)
      Description copied from interface: SSheet
      Sets password to protect sheet, set null to unprotect it.
    • getHashedPassword

      public short getHashedPassword()
      Description copied from interface: SSheet
      Internal Use only.
      Returns:
    • getViewInfo

      public SSheetViewInfo getViewInfo()
    • getPrintSetup

      public SPrintSetup getPrintSetup()
    • addDataValidation

      public SDataValidation addDataValidation(CellRegion region)
    • addDataValidation

      public SDataValidation addDataValidation(CellRegion region, SDataValidation src)
    • getDataValidation

      public SDataValidation getDataValidation(String validationid)
    • deleteDataValidation

      public void deleteDataValidation(SDataValidation validationid)
    • deleteDataValidationRegion

      public List<SDataValidation> deleteDataValidationRegion(CellRegion region)
      Description copied from interface: SSheet
      Delete data validations that are covered by the specified region.
      Parameters:
      region - the cover region
      Returns:
      the data validations deleted
    • getDataValidations

      public List<SDataValidation> getDataValidations()
    • getNumOfDataValidation

      public int getNumOfDataValidation()
    • getDataValidation

      public SDataValidation getDataValidation(int idx)
    • getDataValidation

      public SDataValidation getDataValidation(int rowIdx, int columnIdx)
      Returns:
      the first data validation at row, column
    • getAutoFilter

      public SAutoFilter getAutoFilter()
      Description copied from interface: SSheet
      Gets the auto filter information if there is.
      Returns:
      the auto filter, or null if not found
    • createAutoFilter

      public SAutoFilter createAutoFilter(CellRegion region)
      Description copied from interface: SSheet
      Creates a new auto filter, the old one will be drop directly.
      Parameters:
      region - the auto filter region
      Returns:
      the new auto filter.
    • deleteAutoFilter

      public void deleteAutoFilter()
      Description copied from interface: SSheet
      Delete current autofilter if it has
    • clearAutoFilter

      public void clearAutoFilter()
      Description copied from interface: SSheet
      Clear auto filter if there is.
    • pasteCell

      public CellRegion pasteCell(SheetRegion src, CellRegion dest, PasteOption option)
      Description copied from interface: SSheet
      paste cell from src sheet to this sheet, the sheets must in same book
      Parameters:
      src - src sheet and it's region to paste
      dest - destination region in this sheet
      option - the copy option
      Returns:
      the final effected region
    • getSheetProtection

      public SSheetProtection getSheetProtection()
      Description copied from interface: SSheet
      Gets enhanced protection.
    • setHashedPassword

      public void setHashedPassword(short hashpass)
      Description copied from interface: SSheet
      Internal User only.
    • getSheetVisible

      public SSheet.SheetVisible getSheetVisible()
      Description copied from interface: SSheet
      Get the sheet current visible state.
    • setSheetVisible

      public void setSheetVisible(SSheet.SheetVisible state)
      Description copied from interface: SSheet
      Set the sheet current visible state.
    • addTable

      public void addTable(STable table)
      Description copied from interface: SSheet
      Add a new table
    • getTables

      public List<STable> getTables()
      Description copied from interface: SSheet
      Get tables in this sheet
      Returns:
    • removeTable

      public void removeTable(String name)
      Description copied from interface: SSheet
      Remove the table of the specified table name.
    • getTableByRowCol

      public STable getTableByRowCol(int rowIdx, int colIdx)
      Specified by:
      getTableByRowCol in class AbstractSheetAdv
    • isHidden

      public boolean isHidden(int rowIdx, int colIdx)
      Specified by:
      isHidden in class AbstractSheetAdv
    • isRowHidden

      public boolean isRowHidden(int rowIdx)
      Specified by:
      isRowHidden in class AbstractSheetAdv
    • isFiltered

      public boolean isFiltered()
      Specified by:
      isFiltered in class AbstractSheetAdv
    • removeTables

      public void removeTables(Set<String> tableNames)
      Specified by:
      removeTables in class AbstractSheetAdv
    • removeTable

      public void removeTable(STable table)
      Specified by:
      removeTable in class AbstractSheetAdv
    • clearTables

      public void clearTables()
      Specified by:
      clearTables in class AbstractSheetAdv
    • setHashValue

      public void setHashValue(String hashValue)
      Description copied from interface: SSheet
      New way of hashing sheet protection password.
    • getHashValue

      public String getHashValue()
    • setSpinCount

      public void setSpinCount(String spinCount)
      Description copied from interface: SSheet
      New way of hashing sheet protection password.
    • getSpinCount

      public String getSpinCount()
    • setSaltValue

      public void setSaltValue(String saltValue)
      Description copied from interface: SSheet
      New way of hashing sheet protection password.
    • getSaltValue

      public String getSaltValue()
    • setAlgName

      public void setAlgName(String algName)
      Description copied from interface: SSheet
      New way of hashing sheet protection password.
    • getAlgName

      public String getAlgName()
    • checkMergedRegion

      public CellRegion checkMergedRegion(CellRegion region)
    • addDirectlyMergedRegion

      public void addDirectlyMergedRegion(CellRegion region)
    • getConditionalFormattings

      public List<SConditionalFormatting> getConditionalFormattings()
      Description copied from interface: SSheet
      Returns the conditional formatting applied to this sheet.
      Returns:
    • getSheetConditionalFormattings

      public List<SConditionalFormatting> getSheetConditionalFormattings()
      Specified by:
      getSheetConditionalFormattings in class AbstractSheetAdv
    • addConditionalFormatting

      public void addConditionalFormatting(SConditionalFormatting scf)
      Specified by:
      addConditionalFormatting in class AbstractSheetAdv
    • setMergeOutOfSync

      public void setMergeOutOfSync(int state)
      Specified by:
      setMergeOutOfSync in class AbstractSheetAdv
    • getMergeOutOfSync

      public int getMergeOutOfSync()
      Specified by:
      getMergeOutOfSync in class AbstractSheetAdv
    • getDataRegion

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

      public ConditionalStyleImpl getConditionalFormattingStyle(int row, int col)
      Specified by:
      getConditionalFormattingStyle in class AbstractSheetAdv
    • removeConditionalFormatting

      public void removeConditionalFormatting(SConditionalFormatting scf)
      Specified by:
      removeConditionalFormatting in class AbstractSheetAdv
    • addConditionalFormatting

      public SConditionalFormatting addConditionalFormatting(CellRegion srcrgn, CellRegion dstrgn, SConditionalFormatting src, int rowOff, int colOff)
      Description copied from class: AbstractSheetAdv
      Paste from src a new ConditionalFormatting at the specified region.
      Specified by:
      addConditionalFormatting in class AbstractSheetAdv
      Returns:
    • nextConditionalId

      public int nextConditionalId()
      Specified by:
      nextConditionalId in class AbstractSheetAdv
    • getConditionalFormatting

      public SConditionalFormatting getConditionalFormatting(int id)
      Specified by:
      getConditionalFormatting in class AbstractSheetAdv
    • getConditionalFormatting

      public SConditionalFormatting getConditionalFormatting(int row, int col)
      Specified by:
      getConditionalFormatting in class AbstractSheetAdv
      Returns:
      the associated conditionalFormattingRule
    • deleteConditionalFormatting

      public void deleteConditionalFormatting(SConditionalFormatting cfmt)
      Description copied from class: AbstractSheetAdv
      Delete a conditional formatting from this sheet.
      Specified by:
      deleteConditionalFormatting in class AbstractSheetAdv
    • removeConditionalFormattingRegion

      public void removeConditionalFormattingRegion(CellRegion region)
      Description copied from class: AbstractSheetAdv
      Remove a region from conditional formatting.
      Specified by:
      removeConditionalFormattingRegion in class AbstractSheetAdv
    • deleteConditionalFormattingRegion

      public List<SConditionalFormatting> deleteConditionalFormattingRegion(CellRegion region)
      Description copied from class: AbstractSheetAdv
      Delete a region from conditional formatting and return the deleted conditional formatting.
      Specified by:
      deleteConditionalFormattingRegion in class AbstractSheetAdv
      Returns:
    • setArrayFormula

      public CellRegion setArrayFormula(String formula, CellRegion region)
      Description copied from interface: SSheet
      Sets array formula to specified region for result.

      Note if there are shared formulas this will invalidate any FormulaEvaluator instances based on this workbook

      Parameters:
      formula - text representation of the formula
      region - Region of array formula for result.
      Returns:
      the CellRegion of cells affected by this change
    • removeArrayFormula

      public CellRegion removeArrayFormula(SCell cell)
      Description copied from interface: SSheet
      Remove an Array Formula from this sheet. All cells contained in the Array Formula range are removed as well
      Parameters:
      cell - any cell within Array Formula range
      Returns:
      the CellRegion of cells affected by this change
    • getCellRegionInArrayFormula

      public CellRegion getCellRegionInArrayFormula(SCell cell)
      Description copied from interface: SSheet
      Returns the cell regin if the given cell is in an array formula.
    • getAllArrayFormulas

      public List<CellRegion> getAllArrayFormulas()
      Description copied from interface: SSheet
      Returns all cell regions of array formula in the given sheet
      Specified by:
      getAllArrayFormulas in interface SSheet
      Specified by:
      getAllArrayFormulas in class AbstractSheetAdv
    • setOutlineLevelRow

      public void setOutlineLevelRow(int outlineLevelRow)
      Description copied from interface: SSheet
      Sets the maximum outline level for row represent of this sheet.
    • getOutlineLevelRow

      public int getOutlineLevelRow()
      Description copied from interface: SSheet
      Returns the maximum outline level for row represent.
    • setOutlineLevelCol

      public void setOutlineLevelCol(int outlineLevelCol)
      Description copied from interface: SSheet
      Sets the maximum outline level for column represent of this sheet.
    • getOutlineLevelCol

      public int getOutlineLevelCol()
      Description copied from interface: SSheet
      Returns the maximum outline level for column represent.
    • isApplyStyles

      public boolean isApplyStyles()
      Description copied from interface: SSheet
      Returns whether to apply the styles in outline.

      Default: false

    • setApplyStyles

      public void setApplyStyles(boolean applyStyles)
      Description copied from interface: SSheet
      Sets to apply with the styles in outline.

      Note: Only used for maintaining model state. (not implemented for UI parts)

      Parameters:
      applyStyles - false not to apply
    • isSummaryBelow

      public boolean isSummaryBelow()
      Description copied from interface: SSheet
      Returns whether to display summary below in outline for rows.

      Default: true

    • setSummaryBelow

      public void setSummaryBelow(boolean summaryBelow)
      Description copied from interface: SSheet
      Sets to display summary below in outline for rows.

      Default: true

      Parameters:
      summaryBelow - false to display on top.
    • isSummaryRight

      public boolean isSummaryRight()
      Description copied from interface: SSheet
      Returns whether to display summary right in outline for columns.

      Default: true

    • setSummaryRight

      public void setSummaryRight(boolean summaryRight)
      Description copied from interface: SSheet
      Sets whether to display summary right in outline for columns.

      Default: true

      Parameters:
      summaryRight - false to display on left.
    • isShowOutlineSymbols

      public boolean isShowOutlineSymbols()
      Description copied from interface: SSheet
      Returns whether to display outline symbols.

      Default: true

    • setShowOutlineSymbols

      public void setShowOutlineSymbols(boolean showOutlineSymbols)
      Description copied from interface: SSheet
      Sets whether to display outline symbols.

      Default: true

      Parameters:
      showOutlineSymbols - false not to show.
    • syncOutlineLevelRowTree

      public void syncOutlineLevelRowTree()
    • syncOutlineLevelColTree

      public void syncOutlineLevelColTree()
    • getOutlineLevelRowTree

      public OutlineLevelTree getOutlineLevelRowTree()
    • getOutlineLevelColTree

      public OutlineLevelTree getOutlineLevelColTree()
    • addCellRegionValueChangeListener

      public void addCellRegionValueChangeListener(CellRegion cellRegion, SerializableConsumer<CellRegion> listener)
      Description copied from interface: SSheet
      Adds the listener when specific cell region value change.
    • removeCellRegionValueChangeListener

      public boolean removeCellRegionValueChangeListener(CellRegion cellRegion)
      Description copied from interface: SSheet
      Remove all cell region value change listeners of specific cell region.
      Returns:
      whether the listeners are removed successfully.
    • removeCellRegionValueChangeListener

      public boolean removeCellRegionValueChangeListener(SerializableConsumer<CellRegion> listener)
      Description copied from interface: SSheet
      Remove the cell region value change listener.
      Returns:
      whether the listener is removed successfully.