org.apache.poi.hssf.record.aggregates
Class PageSettingsBlock

java.lang.Object
  extended by org.apache.poi.hssf.record.RecordBase
      extended by org.apache.poi.hssf.record.aggregates.RecordAggregate
          extended by 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'

Author:
Josh Micich

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.poi.hssf.record.aggregates.RecordAggregate
RecordAggregate.PositionTrackingVisitor, RecordAggregate.RecordVisitor
 
Constructor Summary
PageSettingsBlock()
          Creates a PageSettingsBlock with default settings
PageSettingsBlock(RecordStream rs)
           
 
Method Summary
 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()
           
 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 isColumnBroken(int column)
          Queries if the specified column has a page break
static boolean isComponentRecord(int sid)
           
 boolean isRowBroken(int row)
          Queries if the specified row has a page break
 void positionRecords(java.util.List<RecordBase> sheetRecords)
          Some apps can define multiple HeaderFooterRecord records for a sheet.
 void removeColumnBreak(int column)
          Removes a page break at the indicated column
 void removeRowBreak(int row)
          Removes a page break at the indicated row
 void setColumnBreak(short column, short fromRow, short toRow)
          Sets a page break at the indicated column
 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 row
 void shiftColumnBreaks(short startingCol, short endingCol, short count)
          Shifts the vertical page breaks for the indicated count
 void shiftRowBreaks(int startingRow, int endingRow, int count)
          Shifts the horizontal page breaks for the indicated count
 void 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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)
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


removeColumnBreak

public void removeColumnBreak(int column)
Removes a page break at the indicated column


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

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 -

removeRowBreak

public void removeRowBreak(int row)
Removes a page break at the indicated row

Parameters:
row -

isRowBroken

public boolean isRowBroken(int row)
Queries if the specified row has a page break

Parameters:
row -
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

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 -
endingRow -
count -

shiftColumnBreaks

public void shiftColumnBreaks(short startingCol,
                              short endingCol,
                              short count)
Shifts the vertical page breaks for the indicated count

Parameters:
startingCol -
endingCol -
count -

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 the PageSettingsBlock where it belongs.


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:

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.

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(java.util.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


Copyright 2012 The Apache Software Foundation or its licensors, as applicable.