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
-
public final class PageSettingsBlock extends RecordAggregate
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
Constructors Constructor Description PageSettingsBlock()
Creates a PageSettingsBlock with default settingsPageSettingsBlock(RecordStream rs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLateHeaderFooter(HeaderFooterRecord rec)
HEADERFOOTER is new in 2007.void
addLateRecords(RecordStream rs)
This method reads PageSettingsBlock records from the supplied RecordStream until the first non-PageSettingsBlock record is encountered.int[]
getColumnBreaks()
String
getEvenFooter()
String
getEvenHeader()
String
getFirstFooter()
String
getFirstHeader()
FooterRecord
getFooter()
Returns the FooterRecord.HCenterRecord
getHCenter()
HeaderRecord
getHeader()
Returns the HeaderRecord.double
getMargin(short margin)
Gets the size of the margin in inches.int
getNumColumnBreaks()
int
getNumRowBreaks()
PrintSetupRecord
getPrintSetup()
Returns the PrintSetupRecord.int[]
getRowBreaks()
VCenterRecord
getVCenter()
boolean
isAlignMargins()
boolean
isColumnBroken(int column)
Queries if the specified column has a page breakstatic boolean
isComponentRecord(int sid)
boolean
isDiffFirst()
boolean
isDiffOddEven()
boolean
isRowBroken(int row)
Queries if the specified row has a page breakboolean
isScaleWithDoc()
void
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
setAlignMargins(boolean flag)
void
setColumnBreak(short column, short fromRow, short toRow)
Sets a page break at the indicated columnvoid
setDiffFirst(boolean flag)
void
setDiffOddEven(boolean flag)
void
setEvenFooter(String str)
void
setEvenHeader(String str)
void
setFirstFooter(String str)
void
setFirstHeader(String str)
void
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
setScaleWithDoc(boolean flag)
void
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
visitContainedRecords(RecordAggregate.RecordVisitor rv)
Visit each of the atomic BIFF records contained in this RecordAggregate in the order that they should be written to file.-
Methods inherited from class org.apache.poi.hssf.record.aggregates.RecordAggregate
getRecordSize, serialize
-
-
-
-
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 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
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 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
- 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 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
public VCenterRecord getVCenter()
-
getHCenter
public HCenterRecord getHCenter()
-
addLateHeaderFooter
public void addLateHeaderFooter(HeaderFooterRecord rec)
HEADERFOOTER is new in 2007. Some apps seem to have scattered this record long after thePageSettingsBlock
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)
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)
-
-