Class InternalSheet


  • @Internal
    public final class InternalSheet
    extends java.lang.Object
    Low level model implementation of a Sheet (one workbook contains many sheets) This file contains the low level binary records starting at the sheets BOF and ending with the sheets EOF. Use HSSFSheet for a high level representation.

    The structures of the highlevel API use references to this to perform most of their operations. Its probably unwise to use these low level structures directly unless you really know what you're doing. I recommend you read the Microsoft Excel 97 Developer's Kit (Microsoft Press) and the documentation at http://sc.openoffice.org/excelfileformat.pdf before even attempting to use this.

    See Also:
    InternalWorkbook, HSSFSheet
    • Method Detail

      • createSheet

        public static InternalSheet createSheet​(RecordStream rs)
        read support (offset used as starting point for search) for low level API. Pass in an array of Record objects, the sheet number (0 based) and a record offset (should be the location of the sheets BOF record). A Sheet object is constructed and passed back with all of its initialization set to the passed in records and references to those records held. This function is normally called via Workbook.
        Parameters:
        rs - the stream to read records from
        Returns:
        Sheet object with all values set to those read from the file
        See Also:
        InternalWorkbook, Record
      • cloneSheet

        public InternalSheet cloneSheet()
        Clones the low level records of this sheet and returns the new sheet instance. This method is implemented by adding methods for deep cloning to all records that can be added to a sheet. The Record object does not implement cloneable. When adding a new record, implement a public clone method if and only if the record belongs to a sheet.
        Returns:
        the cloned sheet
      • createSheet

        public static InternalSheet createSheet()
        Creates a sheet with all the usual records minus values and the "index" record (not required). Sets the location pointer to where the first value records should go. Use this to create a sheet from "scratch".
        Returns:
        Sheet object with all values set to defaults
      • updateFormulasAfterCellShift

        public void updateFormulasAfterCellShift​(FormulaShifter shifter,
                                                 int externSheetIndex)
        Updates formulas in cells and conditional formats due to moving of cells
        Parameters:
        shifter - the formular shifter
        externSheetIndex - the externSheet index of this sheet
      • addMergedRegion

        public int addMergedRegion​(int rowFrom,
                                   int colFrom,
                                   int rowTo,
                                   int colTo)
      • removeMergedRegion

        public void removeMergedRegion​(int index)
      • getNumMergedRegions

        public int getNumMergedRegions()
      • setDimensions

        public void setDimensions​(int firstrow,
                                  short firstcol,
                                  int lastrow,
                                  short lastcol)
        Per an earlier reported bug in working with Andy Khan's excel read library. This sets the values in the sheet's DimensionsRecord object to be correct. Excel doesn't really care, but we want to play nice with other libraries.
        Parameters:
        firstrow - the first row index
        firstcol - the first column index
        lastrow - the last row index
        lastcol - the last column index
        See Also:
        DimensionsRecord
      • addValueRecord

        public void addValueRecord​(int row,
                                   CellValueRecordInterface col)
        Adds a value record to the sheet's contained binary records (i.e. LabelSSTRecord or NumberRecord).

        This method is "loc" sensitive. Meaning you need to set LOC to where you want it to start searching. If you don't know do this: setLoc(getDimsLoc). When adding several rows you can just start at the last one by leaving loc at what this sets it to.

        Parameters:
        row - the row to add the cell value to
        col - the cell value record itself.
      • removeValueRecord

        public void removeValueRecord​(int row,
                                      CellValueRecordInterface col)
        remove a value record from the records array. This method is not loc sensitive, it resets loc to = dimsloc so no worries.
        Parameters:
        row - - the row of the value record you wish to remove
        col - - a record supporting the CellValueRecordInterface.
        See Also:
        CellValueRecordInterface
      • replaceValueRecord

        public void replaceValueRecord​(CellValueRecordInterface newval)
        replace a value record from the records array. This method is not loc sensitive, it resets loc to = dimsloc so no worries.
        Parameters:
        newval - - a record supporting the CellValueRecordInterface. this will replace the cell value with the same row and column. If there isn't one, one will be added.
      • addRow

        public void addRow​(RowRecord row)
        Adds a row record to the sheet

        This method is "loc" sensitive. Meaning you need to set LOC to where you want it to start searching. If you don't know do this: setLoc(getDimsLoc). When adding several rows you can just start at the last one by leaving loc at what this sets it to.

        Parameters:
        row - the row record to be added
      • removeRow

        public void removeRow​(RowRecord row)
        Removes a row record This method is not loc sensitive, it resets loc to = dimsloc so no worries.
        Parameters:
        row - the row record to remove
      • getCellValueIterator

        public java.util.Iterator<CellValueRecordInterface> getCellValueIterator()
        Get all the value records (from LOC). Records will be returned from the first record (starting at LOC) which is a value record.

        This method is "loc" sensitive. Meaning you need to set LOC to where you want it to start searching. If you don't know do this: setLoc(getDimsLoc). When adding several rows you can just start at the last one by leaving loc at what this sets it to. For this method, set loc to dimsloc to start with, subsequent calls will return values in (physical) sequence or NULL when you get to the end.

        Returns:
        Iterator of CellValueRecordInterface representing the value records
      • getNextRow

        public RowRecord getNextRow()
        get the NEXT RowRecord (from LOC). The first record that is a Row record (starting at LOC) will be returned.

        This method is "loc" sensitive. Meaning you need to set LOC to where you want it to start searching. If you don't know do this: setLoc(getDimsLoc). When adding several rows you can just start at the last one by leaving loc at what this sets it to. For this method, set loc to dimsloc to start with. subsequent calls will return rows in (physical) sequence or NULL when you get to the end.

        Returns:
        RowRecord representing the next row record or NULL if there are no more
      • getRow

        public RowRecord getRow​(int rownum)
        get the NEXT (from LOC) RowRecord where rownumber matches the given rownum. The first record that is a Row record (starting at LOC) that has the same rownum as the given rownum will be returned.

        This method is "loc" sensitive. Meaning you need to set LOC to where you want it to start searching. If you don't know do this: setLoc(getDimsLoc). When adding several rows you can just start at the last one by leaving loc at what this sets it to. For this method, set loc to dimsloc to start with. subsequent calls will return rows in (physical) sequence or NULL when you get to the end.

        Parameters:
        rownum - which row to return (careful with LOC)
        Returns:
        RowRecord representing the next row record or NULL if there are no more
      • getDefaultColumnWidth

        public int getDefaultColumnWidth()
        get the default column width for the sheet (if the columns do not define their own width)
        Returns:
        default column width
      • isGridsPrinted

        public boolean isGridsPrinted()
        Returns:
        true if gridlines are printed
      • setGridsPrinted

        public void setGridsPrinted​(boolean value)
        set whether gridlines printed or not.
        Parameters:
        value - True if gridlines printed.
      • setDefaultColumnWidth

        public void setDefaultColumnWidth​(int dcw)
        set the default column width for the sheet (if the columns do not define their own width)
        Parameters:
        dcw - default column width
      • setDefaultRowHeight

        public void setDefaultRowHeight​(short dch)
        set the default row height for the sheet (if the rows do not define their own height)
        Parameters:
        dch - the default row height
      • getDefaultRowHeight

        public short getDefaultRowHeight()
        get the default row height for the sheet (if the rows do not define their own height)
        Returns:
        default row height
      • getColumnWidth

        public int getColumnWidth​(int columnIndex)
        get the width of a given column in units of 1/256th of a character width
        Parameters:
        columnIndex - index
        Returns:
        column width in units of 1/256th of a character width
        See Also:
        DefaultColWidthRecord, ColumnInfoRecord, setColumnWidth(int, int)
      • getXFIndexForColAt

        public short getXFIndexForColAt​(short columnIndex)
        get the index to the ExtendedFormatRecord "associated" with the column at specified 0-based index. (In this case, an ExtendedFormatRecord index is actually associated with a ColumnInfoRecord which spans 1 or more columns)

        Returns the index to the default ExtendedFormatRecord (0xF) if no ColumnInfoRecord exists that includes the column index specified.

        Parameters:
        columnIndex - the column index
        Returns:
        index of ExtendedFormatRecord associated with ColumnInfoRecord that includes the column index or the index of the default ExtendedFormatRecord (0xF)
      • setColumnWidth

        public void setColumnWidth​(int column,
                                   int width)
        set the width for a given column in 1/256th of a character width units
        Parameters:
        column - - the column number
        width - (in units of 1/256th of a character width)
      • setColumnHidden

        public void setColumnHidden​(int column,
                                    boolean hidden)
        Get the hidden property for a given column.
        Parameters:
        column - - the column number
        hidden - - whether the column is hidden or not
      • setDefaultColumnStyle

        public void setDefaultColumnStyle​(int column,
                                          int styleIndex)
      • groupColumnRange

        public void groupColumnRange​(int fromColumn,
                                     int toColumn,
                                     boolean indent)
        Creates an outline group for the specified columns.
        Parameters:
        fromColumn - group from this column (inclusive)
        toColumn - group to this column (inclusive)
        indent - if true the group will be indented by one level, if false indenting will be removed by one level.
      • getTopRow

        public short getTopRow()
      • setTopRow

        public void setTopRow​(short topRow)
      • setLeftCol

        public void setLeftCol​(short leftCol)
        Sets the left column to show in desktop window pane.
        Parameters:
        leftCol - the left column to show in desktop window pane
      • getLeftCol

        public short getLeftCol()
      • getActiveCellRow

        public int getActiveCellRow()
        Returns the active row
        Returns:
        row the active row index
        See Also:
        SelectionRecord
      • setActiveCellRow

        public void setActiveCellRow​(int row)
        Sets the active row
        Parameters:
        row - the row index
        See Also:
        SelectionRecord
      • getActiveCellCol

        public short getActiveCellCol()
        Returns:
        column of the active cell
        See Also:
        SelectionRecord
      • setActiveCellCol

        public void setActiveCellCol​(short col)
        Sets the active column
        Parameters:
        col - the column index
        See Also:
        SelectionRecord
      • getRecords

        public java.util.List<RecordBase> getRecords()
      • getGridsetRecord

        public GridsetRecord getGridsetRecord()
        Gets the gridset record for this sheet.
        Returns:
        the gridset record for this sheet
      • findFirstRecordBySid

        public Record findFirstRecordBySid​(short sid)
        Returns the first occurrence of a record matching a particular sid.
        Parameters:
        sid - the sid to search for
        Returns:
        the matching record or null if it wasn't found
      • setSCLRecord

        public void setSCLRecord​(SCLRecord sclRecord)
        Sets the SCL record or creates it in the correct place if it does not already exist.
        Parameters:
        sclRecord - The record to set.
      • findFirstRecordLocBySid

        public int findFirstRecordLocBySid​(short sid)
        Finds the first occurrence of a record matching a particular sid and returns it's position.
        Parameters:
        sid - the sid to search for
        Returns:
        the record position of the matching record or -1 if no match is made.
      • getPrintGridlines

        public PrintGridlinesRecord getPrintGridlines()
        Returns the PrintGridlinesRecord.
        Returns:
        PrintGridlinesRecord for the sheet.
      • setPrintGridlines

        public void setPrintGridlines​(PrintGridlinesRecord newPrintGridlines)
        Sets the PrintGridlinesRecord.
        Parameters:
        newPrintGridlines - The new PrintGridlinesRecord for the sheet.
      • getPrintHeaders

        public PrintHeadersRecord getPrintHeaders()
        Returns the PrintHeadersRecord.
        Returns:
        PrintHeadersRecord for the sheet.
      • setPrintHeaders

        public void setPrintHeaders​(PrintHeadersRecord newPrintHeaders)
        Sets the PrintHeadersRecord.
        Parameters:
        newPrintHeaders - The new PrintHeadersRecord for the sheet.
      • setSelected

        public void setSelected​(boolean sel)
        Sets whether the sheet is selected
        Parameters:
        sel - True to select the sheet, false otherwise.
      • createFreezePane

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

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

        Parameters:
        colSplit - Horizonatal position of split.
        rowSplit - Vertical position of split.
        topRow - Top row visible in bottom pane
        leftmostColumn - Left column visible in right pane.
      • createSplitPane

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

        public PaneInformation getPaneInformation()
        Returns the information regarding the currently configured pane (split or freeze).
        Returns:
        null if no pane configured, or the pane information.
      • setDisplayGridlines

        public void setDisplayGridlines​(boolean show)
        Sets whether the gridlines are shown in a viewer.
        Parameters:
        show - whether to show gridlines or not
      • isDisplayGridlines

        public boolean isDisplayGridlines()
        Returns:
        true if gridlines are displayed
      • setDisplayFormulas

        public void setDisplayFormulas​(boolean show)
        Sets whether the formulas are shown in a viewer.
        Parameters:
        show - whether to show formulas or not
      • isDisplayFormulas

        public boolean isDisplayFormulas()
        Returns if formulas are displayed.
        Returns:
        whether formulas are displayed
      • setDisplayRowColHeadings

        public void setDisplayRowColHeadings​(boolean show)
        Sets whether the RowColHeadings are shown in a viewer.
        Parameters:
        show - whether to show RowColHeadings or not
      • isDisplayRowColHeadings

        public boolean isDisplayRowColHeadings()
        Returns if RowColHeadings are displayed.
        Returns:
        whether RowColHeadings are displayed
      • setPrintRowColHeadings

        public void setPrintRowColHeadings​(boolean show)
        Sets whether the RowColHeadings are shown in a viewer.
        Parameters:
        show - whether to show RowColHeadings or not
      • isPrintRowColHeadings

        public boolean isPrintRowColHeadings()
        Returns if RowColHeadings are displayed.
        Returns:
        whether RowColHeadings are displayed
      • getUncalced

        public boolean getUncalced()
        Returns:
        whether an uncalced record must be inserted or not at generation
      • setUncalced

        public void setUncalced​(boolean uncalced)
        Parameters:
        uncalced - whether an uncalced record must be inserted or not at generation
      • aggregateDrawingRecords

        public int aggregateDrawingRecords​(DrawingManager2 drawingManager,
                                           boolean createIfMissing)
        Finds the DrawingRecord for our sheet, and attaches it to the DrawingManager (which knows about the overall DrawingGroup for our workbook). If requested, will create a new DrawRecord if none currently exist
        Parameters:
        drawingManager - The DrawingManager2 for our workbook
        createIfMissing - Should one be created if missing?
        Returns:
        location of EscherAggregate record. if no EscherAggregate record is found return -1
      • preSerialize

        public void preSerialize()
        Perform any work necessary before the sheet is about to be serialized. For instance the escher aggregates size needs to be calculated before serialization so that the dgg record (which occurs first) can be written.
      • setColumnGroupCollapsed

        public void setColumnGroupCollapsed​(int columnNumber,
                                            boolean collapsed)
      • groupRowRange

        public void groupRowRange​(int fromRow,
                                  int toRow,
                                  boolean indent)
      • getOrCreateDataValidityTable

        public DataValidityTable getOrCreateDataValidityTable()
      • getNoteRecords

        public NoteRecord[] getNoteRecords()
        Get the NoteRecords (related to cell comments) for this sheet
        Returns:
        never null, typically empty array
      • getColumnOutlineLevel

        public int getColumnOutlineLevel​(int columnIndex)
      • getMinColumnIndex

        public int getMinColumnIndex()
      • getMaxColumnIndex

        public int getMaxColumnIndex()