Class PageSettingsBlock
java.lang.Object
org.apache.poi.hssf.record.RecordBase
org.apache.poi.hssf.record.aggregates.RecordAggregate
org.apache.poi.hssf.record.aggregates.PageSettingsBlock
Groups the page settings records for a worksheet.
See OOO excelfileformat.pdf sec 4.4 'Page Settings Block'
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.poi.hssf.record.aggregates.RecordAggregate
RecordAggregate.PositionTrackingVisitor, RecordAggregate.RecordVisitor
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a PageSettingsBlock with default settings -
Method Summary
Modifier and TypeMethodDescriptionvoid
HEADERFOOTER is new in 2007.void
This method reads PageSettingsBlock records from the supplied RecordStream until the first non-PageSettingsBlock record is encountered.int[]
Returns the FooterRecord.Returns the HeaderRecord.double
getMargin
(short margin) Gets the size of the margin in inches.int
int
Returns the PrintSetupRecord.int[]
boolean
isColumnBroken
(int column) Queries if the specified column has a page breakstatic boolean
isComponentRecord
(int sid) boolean
isRowBroken
(int row) Queries if the specified row has a page breakvoid
positionRecords
(List<RecordBase> sheetRecords) Some apps can define multiple HeaderFooterRecord records for a sheet.void
removeColumnBreak
(int column) Removes a page break at the indicated columnvoid
removeRowBreak
(int row) Removes a page break at the indicated rowvoid
setColumnBreak
(short column, short fromRow, short toRow) Sets a page break at the indicated columnvoid
setFooter
(FooterRecord newFooter) Sets the FooterRecord.void
setHeader
(HeaderRecord newHeader) Sets the HeaderRecord.void
setMargin
(short margin, double size) Sets the size of the margin in inches.void
setPrintSetup
(PrintSetupRecord newPrintSetup) Sets the PrintSetupRecord.void
setRowBreak
(int row, short fromCol, short toCol) Sets a page break at the indicated rowvoid
shiftColumnBreaks
(short startingCol, short endingCol, short count) Shifts the vertical page breaks for the indicated countvoid
shiftRowBreaks
(int startingRow, int endingRow, int count) Shifts the horizontal page breaks for the indicated countvoid
Visit each of the atomic BIFF records contained in thisRecordAggregate
in the order that they should be written to file.Methods inherited from class org.apache.poi.hssf.record.aggregates.RecordAggregate
getRecordSize, serialize
-
Constructor Details
-
PageSettingsBlock
-
PageSettingsBlock
public PageSettingsBlock()Creates a PageSettingsBlock with default settings
-
-
Method Details
-
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 tofromRow
- the starting rowtoRow
- 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
Description copied from class:RecordAggregate
Visit each of the atomic BIFF records contained in thisRecordAggregate
in the order that they should be written to file. Implementors may or may not return the actualRecord
s being used to manage POI's internal implementation. Callers should not assume either way, and therefore only attempt to modify thoseRecord
s after cloning- Specified by:
visitContainedRecords
in classRecordAggregate
-
getHeader
Returns the HeaderRecord.- Returns:
- HeaderRecord for the sheet.
-
setHeader
Sets the HeaderRecord.- Parameters:
newHeader
- The new HeaderRecord for the sheet.
-
getPrintSetup
Returns the PrintSetupRecord.- Returns:
- PrintSetupRecord for the sheet.
-
setPrintSetup
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 getsize
- 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 rowfromCol
- the starting columntoCol
- 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 rowendingRow
- the ending rowcount
- 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 columnendingCol
- the ending columncount
- 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
-
getVCenter
-
getHCenter
-
addLateRecords
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)
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
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
-