Class BookImpl

All Implemented Interfaces:
SBook, EvaluationContributorContainer, Serializable

public class BookImpl extends AbstractBookAdv
Since:
3.5.0
Author:
dennis
See Also:
  • Constructor Details

    • BookImpl

      public BookImpl(String bookName)
  • Method Details

    • initDefaultCellStyles

      public void initDefaultCellStyles()
      Specified by:
      initDefaultCellStyles in class AbstractBookAdv
    • setDefaultChartSeriesColors

      public void setDefaultChartSeriesColors(List<SColor> colors)
      Specified by:
      setDefaultChartSeriesColors in class AbstractBookAdv
    • getDefaultChartSeriesColors

      public List<SColor> getDefaultChartSeriesColors()
      Specified by:
      getDefaultChartSeriesColors in class AbstractBookAdv
    • getBookSeries

      public SBookSeries getBookSeries()
      Description copied from interface: SBook
      Get the book series, it contains a group of book that might refer to other by book name
      Returns:
      book series
    • getBookName

      public String getBookName()
      Description copied from interface: SBook
      Get the book name, a book name is unique for book in SBookSeries
      Returns:
      book name;
    • getSheet

      public SSheet getSheet(int i)
      Description copied from interface: SBook
      Get sheet at the index
      Parameters:
      i - the sheet index
      Returns:
      the sheet at the index
    • getNumOfSheet

      public int getNumOfSheet()
      Description copied from interface: SBook
      Get the number of sheet
      Returns:
      the number of sheet
    • getSheetByName

      public SSheet getSheetByName(String name)
      Description copied from interface: SBook
      Get the sheet by name
      Parameters:
      name - the name of sheet
      Returns:
      the sheet, or null if not found
    • getSheetById

      public SSheet getSheetById(String id)
      Description copied from interface: SBook
      Get the sheet by id
      Parameters:
      id - the id of sheet
      Returns:
      the sheet, or null if not found
    • checkOwnership

      protected void checkOwnership(SSheet sheet)
    • checkOwnership

      protected void checkOwnership(SName name)
    • startBatchNotificationMode

      public void startBatchNotificationMode()
      Description copied from class: AbstractBookAdv
      Starts a batch mode for event notification in a workbook. Note: all the subsequence event will put in a queue or be ignored it if that event has a duplicated one already inside the queue, and then all the events are triggered until AbstractBookAdv.stopBatchNotificationMode() is invoked.

      Usage:

      
       try {
          book.startBatchNotificationMode();
          // do something here to send events.
        } finally {
          book.stopBatchNotificationMode(); // ensure this will be invoked finally
        }
        

      Specified by:
      startBatchNotificationMode in class AbstractBookAdv
      See Also:
    • stopBatchNotificationMode

      public void stopBatchNotificationMode()
      Description copied from class: AbstractBookAdv
      Stops the batch mode for event notification when triggers all of the events in a queue.
      Specified by:
      stopBatchNotificationMode in class AbstractBookAdv
    • sendModelEvent

      public void sendModelEvent(ModelEvent event)
      Specified by:
      sendModelEvent in class AbstractBookAdv
    • createSheet

      public SSheet createSheet(String name)
      Description copied from interface: SBook
      Create a sheet
      Parameters:
      name - the name of sheet
      Returns:
      the sheet
    • createSheet

      public SSheet createSheet(String name, SSheet src)
      Description copied from interface: SBook
      Create a sheet and copy the content from the specified src sheet; note the owner book of the specified src sheet can be different from this book.
      Parameters:
      name - the name of the new created sheet; null would try to use the sheet name of the specified src sheet; if the same sheet name already used in this book then use default "SheetX" name where X is the next sheet number of this book.
      src - the source sheet to copy
      Returns:
      the sheet
      See Also:
    • createSheet

      public SSheet createSheet(String name, SSheet src, boolean valueOnly)
      Description copied from interface: SBook
      Create a sheet and copy the content from the specified src sheet; note the owner book of the specified src sheet can be different from this book.
      Parameters:
      name - the name of the new created sheet; null would try to use the sheet name of the specified src sheet; if the same sheet name already used in this book then use default "SheetX" name where X is the next sheet number of this book.
      src - the source sheet to copy
      valueOnly - true to copy cell value only
      Returns:
      the sheet
    • getRef

      protected Ref getRef()
    • setSheetName

      public void setSheetName(SSheet sheet, String newname)
      Description copied from interface: SBook
      Set the sheet to a new name
      Parameters:
      sheet - the sheet
      newname - the new name
    • deleteSheet

      public void deleteSheet(SSheet sheet)
      Description copied from interface: SBook
      Delete the sheet
      Parameters:
      sheet - the sheet
    • moveSheetTo

      public void moveSheetTo(SSheet sheet, int index)
      Description copied from interface: SBook
      Move the sheet to new position
      Parameters:
      sheet - the sheet
      index - the new position
    • dump

      public void dump(StringBuilder builder)
    • getDefaultCellStyle

      public SCellStyle getDefaultCellStyle()
      Description copied from interface: SBook
      Get the default style of this book
      Returns:
    • getDefaultCellStyle

      public SCellStyle getDefaultCellStyle(int index)
      Description copied from interface: SBook
      Get the nth default style of this book
      Returns:
    • getDefaultImmutableCellStyle

      public SCellStyle getDefaultImmutableCellStyle()
    • geImmutableCellStyleTable

      public Map<SCellStyle,SCellStyle> geImmutableCellStyleTable()
    • getDefaultImmutableCellStyle

      public SCellStyle getDefaultImmutableCellStyle(int index)
    • setDefaultCellStyle

      public void setDefaultCellStyle(SCellStyle cellStyle)
      Description copied from interface: SBook
      Set the default style of this book
    • createCellStyle

      public SCellStyle createCellStyle(boolean inStyleTable)
      Description copied from interface: SBook
      Create a cell style
      Parameters:
      inStyleTable - if true, the new created style will be stored inside this book, then you can use SBook.searchCellStyle(CellStyleMatcher) to search and reuse this style.
    • createCellStyle

      public SCellStyle createCellStyle(SCellStyle src, boolean inStyleTable)
      Description copied from interface: SBook
      Create a cell style and copy the style from the src style.
      Parameters:
      src - the source style to copy from.
      inStyleTable - if true, the new created style will be stored inside this book, then you can use SBook.searchCellStyle(CellStyleMatcher) to search and reuse this style.
    • addCellStyle

      public SCellStyleBuilder addCellStyle()
      Description copied from interface: SBook
      Create a cell style builder with default font and store inside this book after built, then you can use SBook.getOrAddCellStyle(SCellStyle) to find and reuse this style.
    • addCellStyle

      public SCellStyleBuilder addCellStyle(SCellStyle src)
      Description copied from interface: SBook
      Create a cell style builder and copy the style from the src style, store inside this book after built, then you can use SBook.getOrAddCellStyle(SCellStyle) to find and reuse this style.
      Parameters:
      src - the source style to copy from.
    • createCellStyle

      public SCellStyleBuilder createCellStyle()
      Description copied from interface: SBook
      Create a cell style builder with default font
    • createCellStyle

      public SCellStyleBuilder createCellStyle(SCellStyle src)
      Description copied from interface: SBook
      Create a cell style builder and copy the style from the src style, store inside this book after built,
      Parameters:
      src - the source style to copy from.
    • getCellStyleTable

      public List<SCellStyle> getCellStyleTable()
    • searchCellStyle

      public SCellStyle searchCellStyle(CellStyleMatcher matcher)
      Description copied from interface: SBook
      Search the style table and return the first matched style.
      Parameters:
      matcher - the style matcher
      Returns:
      the matched style.
    • addExtraStyle

      public void addExtraStyle(SExtraStyle extraStyle)
      Description copied from interface: SBook
      Add one more extra cell style.
    • getExtraStyles

      public List<SExtraStyle> getExtraStyles()
      Description copied from interface: SBook
      Get all extra styles.
    • clearExtraStyles

      public void clearExtraStyles()
      Specified by:
      clearExtraStyles in class AbstractBookAdv
    • searchExtraStyle

      public SExtraStyle searchExtraStyle(CellStyleMatcher matcher)
      Description copied from interface: SBook
      Search the style table and return the first matched style.
      Parameters:
      matcher - the style matcher
      Returns:
      the matched style.
    • getDefaultFont

      public SFont getDefaultFont()
    • getDefaultImmutableFont

      public SFont getDefaultImmutableFont()
    • geImmutableFontTable

      public Map<AbstractFontAdv,AbstractFontAdv> geImmutableFontTable()
    • addFont

      public SFontBuilder addFont()
      Description copied from interface: SBook
      Create a font builder and store inside this book after built, then you can use SBook.searchFont(FontMatcher) to search and reuse this style.
    • addFont

      public SFontBuilder addFont(SFont src)
      Description copied from interface: SBook
      Create a font builder and copy the style from the src style, store inside this book after built, then you can use SBook.searchFont(FontMatcher) to search and reuse this style.
    • createFont

      public SFontBuilder createFont()
      Description copied from interface: SBook
      Create a font builder without storing inside this book after built.
    • createFont

      public SFontBuilder createFont(SFont src)
      Description copied from interface: SBook
      Create a font builder and copy the style from the src style, store inside this book after built, then you can use SBook.searchFont(FontMatcher) to search and reuse this style.
      Parameters:
      src - the source style to copy from.
    • getOrAddFont

      public SFont getOrAddFont(SFont font)
      Description copied from class: AbstractBookAdv
      Get the font which stored in this book, or add it into the book if not found, then you can use SBook.searchFont(FontMatcher) to search and reuse this style.
      Specified by:
      getOrAddFont in class AbstractBookAdv
    • createFont

      public SFont createFont(boolean inFontTable)
    • createFont

      public SFont createFont(SFont src, boolean inFontTable)
    • searchFont

      public SFont searchFont(FontMatcher matcher)
    • getMaxRowSize

      public int getMaxRowSize()
      Description copied from interface: SBook
      Get the max row size of this book
    • getMaxColumnSize

      public int getMaxColumnSize()
      Description copied from interface: SBook
      Get the max column size of this book
    • optimizeCellStyle

      public void optimizeCellStyle()
      Description copied from interface: SBook
      Optimize CellStyle, usually called when export book or after many style operation
    • getFontTable

      public List<SFont> getFontTable()
    • addEventListener

      public void addEventListener(ModelEventListener listener)
      Description copied from interface: SBook
      add event listener to this book
      Parameters:
      listener - the listener
    • removeEventListener

      public void removeEventListener(ModelEventListener listener)
      Description copied from interface: SBook
      remove event listener from this book
      Parameters:
      listener - the listener
    • getAttribute

      public Object getAttribute(String name)
      Description copied from interface: SBook
      Get the runtime custom attribute that stored in this book
      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: SBook
      Set the runtime custom attribute to stored in this book, the attribute is only use for developer to stored runtime data in the book, 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: SBook
      Get the unmodifiable runtime attributes map
      Returns:
    • createColor

      public SColor createColor(byte r, byte g, byte b)
    • createColor

      public SColor createColor(String htmlColor)
    • getSheets

      public List<SSheet> getSheets()
      Description copied from interface: SBook
      Get all sheets
      Returns:
      an unmodifiable sheet list
    • createName

      public SName createName(String namename)
    • createName

      public SName createName(String namename, String sheetName)
      Description copied from interface: SBook
      Create a defined name on specified sheet
      Returns:
      created defined name
    • setNameName

      public void setNameName(SName name, String newname)
    • setNameName

      public void setNameName(SName name, String newname, String sheetName)
    • deleteName

      public void deleteName(SName name)
      Description copied from interface: SBook
      Delete a defined name
    • getNumOfName

      public int getNumOfName()
    • getName

      public SName getName(int idx)
    • getNameByName

      public SName getNameByName(String namename)
    • getNameByName

      public SName getNameByName(String namename, String sheetName)
    • getNames

      public List<SName> getNames()
    • getSheetIndex

      public int getSheetIndex(SSheet sheet)
      Description copied from interface: SBook
      Get the index of sheet
      Parameters:
      sheet - the sheet
      Returns:
      the index
    • getSheetIndex

      public int getSheetIndex(String sheetName)
      Description copied from interface: SBook
      Get the index of sheet
      Parameters:
      sheetName - the sheet
    • setShareScope

      public void setShareScope(String scope)
    • getShareScope

      public String getShareScope()
    • getEvaluationContributor

      public EvaluationContributor getEvaluationContributor()
    • setEvaluationContributor

      public void setEvaluationContributor(EvaluationContributor contributor)
    • getMaxRowIndex

      public int getMaxRowIndex()
      Description copied from interface: SBook
      Get the max row index of this book, it is SBook.getMaxRowSize()-1
    • getMaxColumnIndex

      public int getMaxColumnIndex()
      Description copied from interface: SBook
      Get the max column index of this book, it is SBook.getMaxColumnIndex()-1
    • getId

      public String getId()
      Specified by:
      getId in class AbstractBookAdv
    • addPictureData

      public SPictureData addPictureData(SPicture.Format format, byte[] data)
      Description copied from interface: SBook
      Add SPictureData into this book
      Parameters:
      format - picture format
      data - picture raw data
      Returns:
      the created SPictureData
    • getPictureData

      public SPictureData getPictureData(int index)
      Description copied from interface: SBook
      Get SPictureData of the specified index from this book; null if not exist
      Returns:
      SPictureData of the specified index from this book; null if not exist
    • getPicturesDatas

      public Collection<SPictureData> getPicturesDatas()
      Description copied from interface: SBook
      Returns all SPictureData fo this book.
    • getNamedStyle

      public SNamedStyle getNamedStyle(String name)
      Description copied from interface: SBook
      Get the named style of this book
      Returns:
    • addDefaultCellStyle

      public int addDefaultCellStyle(SCellStyle cellStyle)
      Description copied from interface: SBook
      Add one more default cell style and return its index.
    • getDefaultCellStyles

      public Collection<SCellStyle> getDefaultCellStyles()
      Description copied from interface: SBook
      Get all default cell styles.
      Returns:
    • addNamedCellstyle

      public void addNamedCellstyle(SNamedStyle namedStyle)
      Description copied from interface: SBook
      Add one more named cell style.
    • getNamedStyles

      public Collection<SNamedStyle> getNamedStyles()
      Description copied from interface: SBook
      Get all name styles.
      Returns:
    • clearDefaultCellStyles

      public void clearDefaultCellStyles()
      Specified by:
      clearDefaultCellStyles in class AbstractBookAdv
    • clearNamedStyles

      public void clearNamedStyles()
      Specified by:
      clearNamedStyles in class AbstractBookAdv
    • isDirty

      public boolean isDirty()
      Description copied from interface: SBook
      Get if book is changed
      Returns:
      See Also:
      • #resetDirty()
    • setDirty

      public void setDirty(boolean dirty)
      Description copied from interface: SBook
      Set dirty flag
      See Also:
    • createTableName

      public SName createTableName(STable table)
      Specified by:
      createTableName in class AbstractBookAdv
    • addTable

      public void addTable(STable table)
      Specified by:
      addTable in class AbstractBookAdv
    • getTable

      public STable getTable(String name)
      Specified by:
      getTable in class AbstractBookAdv
    • removeTable

      public STable removeTable(String name)
      Specified by:
      removeTable in class AbstractBookAdv
    • setTableColumnName

      public String setTableColumnName(STable table, String oldName, String newName)
      Specified by:
      setTableColumnName in class AbstractBookAdv
    • getOrCreateDefaultHyperlinkStyle

      public SCellStyle getOrCreateDefaultHyperlinkStyle(SCell cell)
      Description copied from interface: SBook
      Returns existing or create SCellStyle for hyperlink on the specified cell
      Returns:
    • getOrAddDefaultHyperlinkStyle

      public SCellStyle getOrAddDefaultHyperlinkStyle(SCell cell)
      Description copied from interface: SBook
      Returns existing or add cell style for hyperlink on the specified cell
      Parameters:
      cell - the cell with hyperlink
    • initDefaultFont

      public void initDefaultFont()
      Specified by:
      initDefaultFont in class AbstractBookAdv
    • getCharWidth

      public int getCharWidth()
      Office Open XML Part 4: Markup Language Reference 3.3.1.12 col (Column Width & Formatting) The character width 7 is based on Calibri 11 and character width 8 is base on Calibri 12.
      Specified by:
      getCharWidth in class AbstractBookAdv
    • getTableStyle

      public STableStyle getTableStyle(String name)
      Description copied from interface: SBook
      Get table style of the specified name.
      Returns:
    • addTableStyle

      public void addTableStyle(STableStyle tableStyle)
      Description copied from interface: SBook
      Add table style into this book.
    • getTableStyles

      public List<STableStyle> getTableStyles()
      Description copied from interface: SBook
      Returns table styles of this book.
      Returns:
    • clearTableStyles

      public void clearTableStyles()
      Description copied from interface: SBook
      Clear custom table styles of this book.
    • setDefaultPivotStyleName

      public void setDefaultPivotStyleName(String name)
      Description copied from interface: SBook
      Set default pivot style name.
    • getDefaultPivotStyleName

      public String getDefaultPivotStyleName()
      Description copied from interface: SBook
      Get default pivot style name.
      Returns:
    • setDefaultTableStyleName

      public void setDefaultTableStyleName(String name)
      Description copied from interface: SBook
      Set default table style name
    • getDefaultTableStyleName

      public String getDefaultTableStyleName()
      Description copied from interface: SBook
      Get default table style name
      Returns:
    • getDependencyTracer

      public SDependencyTracer getDependencyTracer()
      Description copied from interface: SBook
      Returns the dependency tracer.
      Returns:
    • getWorkbookProtection

      public SWorkbookProtection getWorkbookProtection()
      Description copied from interface: SBook
      Returns the workbook protection
    • setFormulaMaxIterations

      public void setFormulaMaxIterations(int maxIterations)
      Description copied from interface: SBook
      Sets the max iterations of formula
    • getFormulaMaxIterations

      public int getFormulaMaxIterations()
      Description copied from interface: SBook
      Returns the max iterations of formula
    • setFormulaMaxChange

      public void setFormulaMaxChange(double maxChange)
      Description copied from interface: SBook
      Sets the max change of formula
    • getFormulaMaxChange

      public double getFormulaMaxChange()
      Description copied from interface: SBook
      Returns the max change of formula
    • cloneBook

      public SBook cloneBook()
      Description copied from interface: SBook
      Clones a new book.
      Returns:
      a new book
    • getOrAddCellStyle

      public SCellStyle getOrAddCellStyle(SCellStyle src)
      Description copied from interface: SBook
      Get the cell style which stored in this book, add it into the book if not found.
    • getCellStyle

      public SCellStyle getCellStyle(SCellStyle src)
    • getOrAddExtraStyle

      public SExtraStyle getOrAddExtraStyle(SExtraStyle src)
      Description copied from interface: SBook
      Get the extra style which stored in this book, add it into the book if not found.
    • isPostProcessing

      public boolean isPostProcessing()
      Specified by:
      isPostProcessing in class AbstractBookAdv
    • setPostProcessing

      public void setPostProcessing(boolean b)
      Specified by:
      setPostProcessing in class AbstractBookAdv
    • hasSubtotalExpression

      public boolean hasSubtotalExpression()
      Specified by:
      hasSubtotalExpression in class AbstractBookAdv
    • resetSubtotalExpressionCache

      public void resetSubtotalExpressionCache()
      Specified by:
      resetSubtotalExpressionCache in class AbstractBookAdv