Class PageSettingsBlock


  • public final class PageSettingsBlock
    extends RecordAggregate
    Groups the page settings records for a worksheet.

    See OOO excelfileformat.pdf sec 4.4 'Page Settings Block'

    • Constructor Detail

      • PageSettingsBlock

        public PageSettingsBlock​(RecordStream rs)
      • PageSettingsBlock

        public PageSettingsBlock()
        Creates a PageSettingsBlock with default settings
    • Method Detail

      • isComponentRecord

        public static boolean isComponentRecord​(int sid)
        Parameters:
        sid - the record sid
        Returns:
        true if the specified Record sid is one belonging to the 'Page Settings Block'.
      • setColumnBreak

        public void setColumnBreak​(short column,
                                   short fromRow,
                                   short toRow)
        Sets a page break at the indicated column
        Parameters:
        column - the column to add page breaks to
        fromRow - the starting row
        toRow - the ending row
      • removeColumnBreak

        public void removeColumnBreak​(int column)
        Removes a page break at the indicated column
        Parameters:
        column - the column to check for page breaks
      • visitContainedRecords

        public void visitContainedRecords​(RecordAggregate.RecordVisitor rv)
        Description copied from class: RecordAggregate
        Visit each of the atomic BIFF records contained in this RecordAggregate in the order that they should be written to file. Implementors may or may not return the actual Records being used to manage POI's internal implementation. Callers should not assume either way, and therefore only attempt to modify those Records after cloning
        Specified by:
        visitContainedRecords in class RecordAggregate
        Parameters:
        rv - The visitor to use for callbacks while walking this object
      • getHeader

        public HeaderRecord getHeader()
        Returns the HeaderRecord.
        Returns:
        HeaderRecord for the sheet.
      • setHeader

        public void setHeader​(HeaderRecord newHeader)
        Sets the HeaderRecord.
        Parameters:
        newHeader - The new HeaderRecord for the sheet.
      • getFooter

        public FooterRecord getFooter()
        Returns the FooterRecord.
        Returns:
        FooterRecord for the sheet.
      • setFooter

        public void setFooter​(FooterRecord newFooter)
        Sets the FooterRecord.
        Parameters:
        newFooter - The new FooterRecord for the sheet.
      • getPrintSetup

        public PrintSetupRecord getPrintSetup()
        Returns the PrintSetupRecord.
        Returns:
        PrintSetupRecord for the sheet.
      • setPrintSetup

        public void setPrintSetup​(PrintSetupRecord newPrintSetup)
        Sets the PrintSetupRecord.
        Parameters:
        newPrintSetup - The new PrintSetupRecord for the sheet.
      • getMargin

        public double getMargin​(short margin)
        Gets the size of the margin in inches.
        Parameters:
        margin - which margin to get
        Returns:
        the size of the margin
      • setMargin

        public void setMargin​(short margin,
                              double size)
        Sets the size of the margin in inches.
        Parameters:
        margin - which margin to get
        size - the size of the margin
      • setRowBreak

        public void setRowBreak​(int row,
                                short fromCol,
                                short toCol)
        Sets a page break at the indicated row
        Parameters:
        row - the row
        fromCol - the starting column
        toCol - the ending column
      • removeRowBreak

        public void removeRowBreak​(int row)
        Removes a page break at the indicated row
        Parameters:
        row - the row
      • isRowBroken

        public boolean isRowBroken​(int row)
        Queries if the specified row has a page break
        Parameters:
        row - the row to check for
        Returns:
        true if the specified row has a page break
      • isColumnBroken

        public boolean isColumnBroken​(int column)
        Queries if the specified column has a page break
        Parameters:
        column - the column to check for
        Returns:
        true if the specified column has a page break
      • shiftRowBreaks

        public void shiftRowBreaks​(int startingRow,
                                   int endingRow,
                                   int count)
        Shifts the horizontal page breaks for the indicated count
        Parameters:
        startingRow - the starting row
        endingRow - the ending row
        count - the number of rows to shift by
      • shiftColumnBreaks

        public void shiftColumnBreaks​(short startingCol,
                                      short endingCol,
                                      short count)
        Shifts the vertical page breaks for the indicated count
        Parameters:
        startingCol - the starting column
        endingCol - the ending column
        count - the number of columns to shift by
      • getRowBreaks

        public int[] getRowBreaks()
        Returns:
        all the horizontal page breaks, never null
      • getNumRowBreaks

        public int getNumRowBreaks()
        Returns:
        the number of row page breaks
      • getColumnBreaks

        public int[] getColumnBreaks()
        Returns:
        all the column page breaks, never null
      • getNumColumnBreaks

        public int getNumColumnBreaks()
        Returns:
        the number of column page breaks
      • addLateHeaderFooter

        public void addLateHeaderFooter​(HeaderFooterRecord rec)
        HEADERFOOTER is new in 2007. Some apps seem to have scattered this record long after the PageSettingsBlock where it belongs.
        Parameters:
        rec - the HeaderFooterRecord to set
      • addLateRecords

        public void addLateRecords​(RecordStream rs)
        This method reads PageSettingsBlock records from the supplied RecordStream until the first non-PageSettingsBlock record is encountered. As each record is read, it is incorporated into this PageSettingsBlock.

        The latest Excel version seems to write the PageSettingsBlock uninterrupted. However there are several examples (that Excel reads OK) where these records are not written together:

        • HEADER_FOOTER(0x089C) after WINDOW2 - This record is new in 2007. Some apps seem to have scattered this record long after the PageSettingsBlock where it belongs test samples: SharedFormulaTest.xls, ex44921-21902.xls, ex42570-20305.xls
        • PLS, WSBOOL, PageSettingsBlock - WSBOOL is not a PSB record. This happens in the test sample file "NoGutsRecords.xls" and "WORKBOOK_in_capitals.xls"
        • Margins after DIMENSION - All of PSB should be before DIMENSION. (Bug-47199)
        These were probably written by other applications (or earlier versions of Excel). It was decided to not write specific code for detecting each of these cases. POI now tolerates PageSettingsBlock records scattered all over the sheet record stream, and in any order, but does not allow duplicates of any of those records.

        Note - when POI writes out this PageSettingsBlock, the records will always be written in one consolidated block (in the standard ordering) regardless of how scattered the records were when they were originally read.

        Parameters:
        rs - the RecordStream to read from
        Throws:
        RecordFormatException - if any PSB record encountered has the same type (sid) as a record that is already part of this PageSettingsBlock
      • positionRecords

        public void positionRecords​(List<RecordBase> sheetRecords)
        Some apps can define multiple HeaderFooterRecord records for a sheet. When saving such a file Excel 2007 re-positions them according to the following rules: - take a HeaderFooterRecord and read 16-byte GUID at offset 12. If it is zero, it means the current sheet and the given HeaderFooterRecord belongs to this PageSettingsBlock - If GUID is not zero then search in preceding CustomViewSettingsRecordAggregates. Compare first 16 bytes of UserSViewBegin with the HeaderFooterRecord's GUID. If match, then append the HeaderFooterRecord to this CustomViewSettingsRecordAggregates
        Parameters:
        sheetRecords - the list of sheet records read so far
      • isDiffOddEven

        public boolean isDiffOddEven()
        Returns:
        Since:
        3.9.5
      • setDiffOddEven

        public void setDiffOddEven​(boolean flag)
      • isDiffFirst

        public boolean isDiffFirst()
        Returns:
        Since:
        3.9.5
      • setDiffFirst

        public void setDiffFirst​(boolean flag)
      • isScaleWithDoc

        public boolean isScaleWithDoc()
        Returns:
        Since:
        3.9.5
      • setScaleWithDoc

        public void setScaleWithDoc​(boolean flag)
      • isAlignMargins

        public boolean isAlignMargins()
        Returns:
        Since:
        3.9.5
      • setAlignMargins

        public void setAlignMargins​(boolean flag)
      • getEvenHeader

        public String getEvenHeader()
        Returns:
        Since:
        3.9.5
      • setEvenHeader

        public void setEvenHeader​(String str)
      • getEvenFooter

        public String getEvenFooter()
        Returns:
        Since:
        3.9.5
      • setEvenFooter

        public void setEvenFooter​(String str)
      • getFirstHeader

        public String getFirstHeader()
        Returns:
        Since:
        3.9.5
      • setFirstHeader

        public void setFirstHeader​(String str)
      • getFirstFooter

        public String getFirstFooter()
        Returns:
        Since:
        3.9.5
      • setFirstFooter

        public void setFirstFooter​(String str)