Top Description Inners Fields Constructors Methods
org.apache.poi.hssf.record.aggregates

public final Class PageSettingsBlock

extends RecordAggregate
Class Inheritance
Imports
java.util.ArrayList, .HashMap, .Iterator, .List, .Map, org.apache.poi.hssf.model.RecordStream, .InternalSheet, org.apache.poi.hssf.record.*, org.apache.poi.util.HexDump

Groups the page settings records for a worksheet.

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
PageSettingsBlock.PLSAggregate

PLS is potentially a continued record, but is currently uninterpreted by POI

Field Summary

Modifier and TypeField and Description
private Record
private BottomMarginRecord
private PageBreakRecord
private FooterRecord
private HCenterRecord
private HeaderRecord
private HeaderFooterRecord
private LeftMarginRecord
private final List<PageSettingsBlock.PLSAggregate>
private PrintSetupRecord
private Record
private RightMarginRecord
private PageBreakRecord
private final List<HeaderFooterRecord>
_sviewHeaderFooters

HeaderFooterRecord records belonging to preceding CustomViewSettingsRecordAggregates.

private TopMarginRecord
private VCenterRecord

Constructor Summary

AccessConstructor and Description
public
public
PageSettingsBlock()

Creates a PageSettingsBlock with default settings

Method Summary

Modifier and TypeMethod and Description
public void
addLateHeaderFooter(HeaderFooterRecord
the HeaderFooterRecord to set
rec
)

HEADERFOOTER is new in 2007.

public void
addLateRecords(RecordStream
the RecordStream to read from
rs
)

This method reads PageSettingsBlock records from the supplied RecordStream until the first non-PageSettingsBlock record is encountered.

private void
private static HCenterRecord
createHCenter()

creates the HCenter Record and sets it to false (don't horizontally center)

private static PrintSetupRecord

Returns:

record containing a PrintSetupRecord
createPrintSetup
()

creates the PrintSetup Record and sets it to defaults and marks it invalid

private static VCenterRecord
createVCenter()

creates the VCenter Record and sets it to false (don't horizontally center)

public int[]

Returns:

all the column page breaks, never null
getColumnBreaks
()

private PageBreakRecord
public FooterRecord

Returns:

FooterRecord for the sheet.
getFooter
()

Returns the FooterRecord.

public HCenterRecord
public HeaderRecord

Returns:

HeaderRecord for the sheet.
getHeader
()

Returns the HeaderRecord.

public double

Returns:

the size of the margin
getMargin
(short
which margin to get
margin
)

Gets the size of the margin in inches.

private Margin
getMarginRec(int marginIndex)

public int

Returns:

the number of column page breaks
getNumColumnBreaks
()

public int

Returns:

the number of row page breaks
getNumRowBreaks
()

public PrintSetupRecord

Returns:

PrintSetupRecord for the sheet.
getPrintSetup
()

Returns the PrintSetupRecord.

public int[]

Returns:

all the horizontal page breaks, never null
getRowBreaks
()

private PageBreakRecord
public VCenterRecord
public boolean

Returns:

true if the specified column has a page break
isColumnBroken
(int
the column to check for
column
)

Queries if the specified column has a page break

public static boolean

Returns:

true if the specified Record sid is one belonging to the 'Page Settings Block'.
isComponentRecord
(int
the record sid
sid
)

public boolean

Returns:

true if the specified row has a page break
isRowBroken
(int
the row to check for
row
)

Queries if the specified row has a page break

public void
positionRecords(List<RecordBase>
the list of sheet records read so far
sheetRecords
)

Some apps can define multiple HeaderFooterRecord records for a sheet.

private boolean
public void
removeColumnBreak(int
the column to check for page breaks
column
)

Removes a page break at the indicated column

public void
removeRowBreak(int
the row
row
)

Removes a page break at the indicated row

public void
setColumnBreak(short
the column to add page breaks to
column
,
short
the starting row
fromRow
,
short
the ending row
toRow
)

Sets a page break at the indicated column

public void
setFooter(FooterRecord
The new FooterRecord for the sheet.
newFooter
)

Sets the FooterRecord.

public void
setHeader(HeaderRecord
The new HeaderRecord for the sheet.
newHeader
)

Sets the HeaderRecord.

public void
setMargin(short
which margin to get
margin
,
double
the size of the margin
size
)

Sets the size of the margin in inches.

public void
setPrintSetup(PrintSetupRecord
The new PrintSetupRecord for the sheet.
newPrintSetup
)

Sets the PrintSetupRecord.

public void
setRowBreak(int
the row
row
,
short
the starting column
fromCol
,
short
the ending column
toCol
)

Sets a page break at the indicated row

private static void
shiftBreaks(PageBreakRecord
The page record to be shifted
breaks
,
int
Starting "main" value to shift breaks
start
,
int
Ending "main" value to shift breaks
stop
,
int
number of units (rows/columns) to shift by
count
)

Shifts all the page breaks in the range "count" number of rows/columns

public void
shiftColumnBreaks(short
the starting column
startingCol
,
short
the ending column
endingCol
,
short
the number of columns to shift by
count
)

Shifts the vertical page breaks for the indicated count

public void
shiftRowBreaks(int
the starting row
startingRow
,
int
the ending row
endingRow
,
int
the number of rows to shift by
count
)

Shifts the horizontal page breaks for the indicated count

public void
visitContainedRecords(RecordAggregate.RecordVisitor
The visitor to use for callbacks while walking this object
rv
)

Implements abstract org.apache.poi.hssf.record.aggregates.RecordAggregate.visitContainedRecords.

Visit each of the atomic BIFF records contained in this RecordAggregate in the order that they should be written to file.

private static void
private static void
Inherited from org.apache.poi.hssf.record.aggregates.RecordAggregate:
getRecordSizeserialize

Field Detail

_bitmapback to summary
private Record _bitmap
_bottomMarginback to summary
private BottomMarginRecord _bottomMargin
_columnBreaksRecordback to summary
private PageBreakRecord _columnBreaksRecord
_hCenterback to summary
private HCenterRecord _hCenter
_headerback to summary
private HeaderRecord _header
_headerFooterback to summary
private HeaderFooterRecord _headerFooter
_leftMarginback to summary
private LeftMarginRecord _leftMargin
_plsRecordsback to summary
private final List<PageSettingsBlock.PLSAggregate> _plsRecords
_printSetupback to summary
private PrintSetupRecord _printSetup
_printSizeback to summary
private Record _printSize
_rightMarginback to summary
private RightMarginRecord _rightMargin
_rowBreaksRecordback to summary
private PageBreakRecord _rowBreaksRecord
_sviewHeaderFootersback to summary
private final List<HeaderFooterRecord> _sviewHeaderFooters

HeaderFooterRecord records belonging to preceding CustomViewSettingsRecordAggregates. The indicator of such records is a non-zero GUID, see org.apache.poi.hssf.record.HeaderFooterRecord#getGuid()

_topMarginback to summary
private TopMarginRecord _topMargin
_vCenterback to summary
private VCenterRecord _vCenter

Constructor Detail

PageSettingsBlockback to summary
public PageSettingsBlock(RecordStream rs)
PageSettingsBlockback to summary
public PageSettingsBlock()

Creates a PageSettingsBlock with default settings

Method Detail

addLateHeaderFooterback to summary
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:HeaderFooterRecord

the HeaderFooterRecord to set

addLateRecordsback to summary
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:RecordStream

the RecordStream to read from

Exceptions
RecordFormatException:
if any PSB record encountered has the same type (sid) as a record that is already part of this PageSettingsBlock
checkNotPresentback to summary
private void checkNotPresent(Record rec)
createHCenterback to summary
private static HCenterRecord createHCenter()

creates the HCenter Record and sets it to false (don't horizontally center)

createPrintSetupback to summary
private static PrintSetupRecord createPrintSetup()

creates the PrintSetup Record and sets it to defaults and marks it invalid

Returns:PrintSetupRecord

record containing a PrintSetupRecord

See Also
org.apache.poi.hssf.record.PrintSetupRecord, org.apache.poi.hssf.record.Record
createVCenterback to summary
private static VCenterRecord createVCenter()

creates the VCenter Record and sets it to false (don't horizontally center)

getColumnBreaksback to summary
public int[] getColumnBreaks()
Returns:int[]

all the column page breaks, never null

getColumnBreaksRecordback to summary
private PageBreakRecord getColumnBreaksRecord()
getFooterback to summary
public FooterRecord getFooter()

Returns the FooterRecord.

Returns:FooterRecord

FooterRecord for the sheet.

getHCenterback to summary
public HCenterRecord getHCenter()
getHeaderback to summary
public HeaderRecord getHeader()

Returns the HeaderRecord.

Returns:HeaderRecord

HeaderRecord for the sheet.

getMarginback to summary
public double getMargin(short margin)

Gets the size of the margin in inches.

Parameters
margin:short

which margin to get

Returns:double

the size of the margin

getMarginRecback to summary
private Margin getMarginRec(int marginIndex)
getNumColumnBreaksback to summary
public int getNumColumnBreaks()
Returns:int

the number of column page breaks

getNumRowBreaksback to summary
public int getNumRowBreaks()
Returns:int

the number of row page breaks

getPrintSetupback to summary
public PrintSetupRecord getPrintSetup()

Returns the PrintSetupRecord.

Returns:PrintSetupRecord

PrintSetupRecord for the sheet.

getRowBreaksback to summary
public int[] getRowBreaks()
Returns:int[]

all the horizontal page breaks, never null

getRowBreaksRecordback to summary
private PageBreakRecord getRowBreaksRecord()
getVCenterback to summary
public VCenterRecord getVCenter()
isColumnBrokenback to summary
public boolean isColumnBroken(int column)

Queries if the specified column has a page break

Parameters
column:int

the column to check for

Returns:boolean

true if the specified column has a page break

isComponentRecordback to summary
public static boolean isComponentRecord(int sid)
Parameters
sid:int

the record sid

Returns:boolean

true if the specified Record sid is one belonging to the 'Page Settings Block'.

isRowBrokenback to summary
public boolean isRowBroken(int row)

Queries if the specified row has a page break

Parameters
row:int

the row to check for

Returns:boolean

true if the specified row has a page break

positionRecordsback to summary
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:List<RecordBase>

the list of sheet records read so far

readARecordback to summary
private boolean readARecord(RecordStream rs)
removeColumnBreakback to summary
public void removeColumnBreak(int column)

Removes a page break at the indicated column

Parameters
column:int

the column to check for page breaks

removeRowBreakback to summary
public void removeRowBreak(int row)

Removes a page break at the indicated row

Parameters
row:int

the row

setColumnBreakback to summary
public void setColumnBreak(short column, short fromRow, short toRow)

Sets a page break at the indicated column

Parameters
column:short

the column to add page breaks to

fromRow:short

the starting row

toRow:short

the ending row

setFooterback to summary
public void setFooter(FooterRecord newFooter)

Sets the FooterRecord.

Parameters
newFooter:FooterRecord

The new FooterRecord for the sheet.

setHeaderback to summary
public void setHeader(HeaderRecord newHeader)

Sets the HeaderRecord.

Parameters
newHeader:HeaderRecord

The new HeaderRecord for the sheet.

setMarginback to summary
public void setMargin(short margin, double size)

Sets the size of the margin in inches.

Parameters
margin:short

which margin to get

size:double

the size of the margin

setPrintSetupback to summary
public void setPrintSetup(PrintSetupRecord newPrintSetup)

Sets the PrintSetupRecord.

Parameters
newPrintSetup:PrintSetupRecord

The new PrintSetupRecord for the sheet.

setRowBreakback to summary
public void setRowBreak(int row, short fromCol, short toCol)

Sets a page break at the indicated row

Parameters
row:int

the row

fromCol:short

the starting column

toCol:short

the ending column

shiftBreaksback to summary
private static void shiftBreaks(PageBreakRecord breaks, int start, int stop, int count)

Shifts all the page breaks in the range "count" number of rows/columns

Parameters
breaks:PageBreakRecord

The page record to be shifted

start:int

Starting "main" value to shift breaks

stop:int

Ending "main" value to shift breaks

count:int

number of units (rows/columns) to shift by

shiftColumnBreaksback to summary
public void shiftColumnBreaks(short startingCol, short endingCol, short count)

Shifts the vertical page breaks for the indicated count

Parameters
startingCol:short

the starting column

endingCol:short

the ending column

count:short

the number of columns to shift by

shiftRowBreaksback to summary
public void shiftRowBreaks(int startingRow, int endingRow, int count)

Shifts the horizontal page breaks for the indicated count

Parameters
startingRow:int

the starting row

endingRow:int

the ending row

count:int

the number of rows to shift by

visitContainedRecordsback to summary
public void visitContainedRecords(RecordAggregate.RecordVisitor rv)

Implements abstract org.apache.poi.hssf.record.aggregates.RecordAggregate.visitContainedRecords.

Doc from org.apache.poi.hssf.record.aggregates.RecordAggregate.visitContainedRecords.

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

Parameters
rv:RecordAggregate.RecordVisitor

The visitor to use for callbacks while walking this object

Annotations
@Override
visitIfPresentback to summary
private static void visitIfPresent(Record r, RecordAggregate.RecordVisitor rv)
visitIfPresentback to summary
private static void visitIfPresent(PageBreakRecord r, RecordAggregate.RecordVisitor rv)
org.apache.poi.hssf.record.aggregates back to summary

private final Class PageSettingsBlock.PLSAggregate

extends RecordAggregate
Class Inheritance

PLS is potentially a continued record, but is currently uninterpreted by POI

Field Summary

Modifier and TypeField and Description
private final Record
private ContinueRecord[]
_plsContinues

holds any continue records found after the PLS record.

private static final ContinueRecord[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
visitContainedRecords(RecordAggregate.RecordVisitor
The visitor to use for callbacks while walking this object
rv
)

Implements abstract org.apache.poi.hssf.record.aggregates.RecordAggregate.visitContainedRecords.

Visit each of the atomic BIFF records contained in this RecordAggregate in the order that they should be written to file.

Inherited from org.apache.poi.hssf.record.aggregates.RecordAggregate:
getRecordSizeserialize

Field Detail

_plsback to summary
private final Record _pls
_plsContinuesback to summary
private ContinueRecord[] _plsContinues

holds any continue records found after the PLS record.
This would not be required if PLS was properly interpreted. Currently, PLS is an UnknownRecord and does not automatically include any trailing ContinueRecords.

EMPTY_CONTINUE_RECORD_ARRAYback to summary
private static final ContinueRecord[] EMPTY_CONTINUE_RECORD_ARRAY

Constructor Detail

PLSAggregateback to summary
public PLSAggregate(RecordStream rs)

Method Detail

visitContainedRecordsback to summary
public void visitContainedRecords(RecordAggregate.RecordVisitor rv)

Implements abstract org.apache.poi.hssf.record.aggregates.RecordAggregate.visitContainedRecords.

Doc from org.apache.poi.hssf.record.aggregates.RecordAggregate.visitContainedRecords.

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

Parameters
rv:RecordAggregate.RecordVisitor

The visitor to use for callbacks while walking this object

Annotations
@Override