Save This Page
Home » poi-src-3.2-FINAL-20081019 » org.apache » poi » hssf » model » [javadoc | source]
org.apache.poi.hssf.model
public final class: Sheet [javadoc | source]
java.lang.Object
   org.apache.poi.hssf.model.Sheet

All Implemented Interfaces:
    Model

Low level model implementation of a Sheet (one workbook contains many sheets) This file contains the low level binary records starting at the sheets BOF and ending with the sheets EOF. Use HSSFSheet for a high level representation.

The structures of the highlevel API use references to this to perform most of their operations. Its probably unwise to use these low level structures directly unless you really know what you're doing. I recommend you read the Microsoft Excel 97 Developer's Kit (Microsoft Press) and the documentation at http://sc.openoffice.org/excelfileformat.pdf before even attempting to use this.

Field Summary
public static final  short LeftMargin     
public static final  short RightMargin     
public static final  short TopMargin     
public static final  short BottomMargin     
protected  ArrayList records     
 int preoffset     
 int loc     
protected  int dimsloc     
protected  DimensionsRecord dims     
protected  DefaultColWidthRecord defaultcolwidth     
protected  DefaultRowHeightRecord defaultrowheight     
protected  GridsetRecord gridset     
protected  PrintSetupRecord printSetup     
protected  HeaderRecord header     
protected  FooterRecord footer     
protected  PrintGridlinesRecord printGridlines     
protected  WindowTwoRecord windowTwo     
protected  MergeCellsRecord merged     
protected  Margin[] margins     
protected  List mergedRecords     
protected  int numMergedRegions     
protected  SelectionRecord selection     
protected  ColumnInfoRecordsAggregate columns     
protected  ValueRecordsAggregate cells     
protected  RowRecordsAggregate rows     
protected  int eofLoc     
protected  ProtectRecord protect     
protected  PageBreakRecord rowBreaks     
protected  PageBreakRecord colBreaks     
protected  ObjectProtectRecord objprotect     
protected  ScenarioProtectRecord scenprotect     
protected  PasswordRecord password     
protected  List condFormatting     
protected  boolean _isUncalced    Add an UncalcedRecord if not true indicating formulas have not been calculated 
public static final  byte PANE_LOWER_RIGHT     
public static final  byte PANE_UPPER_RIGHT     
public static final  byte PANE_LOWER_LEFT     
public static final  byte PANE_UPPER_LEFT     
Constructor:
 public Sheet() 
Method from org.apache.poi.hssf.model.Sheet Summary:
addConditionalFormatting,   addMergedRegion,   addRow,   addValueRecord,   aggregateDrawingRecords,   checkDimsLoc,   cloneSheet,   createBOF,   createBlank,   createCalcCount,   createCalcMode,   createColInfo,   createDefaultColWidth,   createDefaultRowHeight,   createDelta,   createDimensions,   createEOF,   createFooter,   createFormula,   createFreezePane,   createGridset,   createGuts,   createHCenter,   createHeader,   createIndex,   createIteration,   createLabelSST,   createMergedCells,   createNumber,   createObjectProtect,   createPassword,   createPrintGridlines,   createPrintHeaders,   createPrintSetup,   createProtect,   createRefMode,   createRow,   createSaveRecalc,   createScenarioProtect,   createSelection,   createSheet,   createSheet,   createSheet,   createSplitPane,   createVCenter,   createWSBool,   createWindowTwo,   findFirstRecordBySid,   findFirstRecordLocBySid,   getActiveCellCol,   getActiveCellRow,   getCFRecordsAggregateAt,   getColumnBreaks,   getColumnWidth,   getDefaultColumnWidth,   getDefaultRowHeight,   getDimsLoc,   getEofLoc,   getFooter,   getGridsetRecord,   getHeader,   getLeftCol,   getLoc,   getMargin,   getMargins,   getMergedRegionAt,   getNextRow,   getNextValueRecord,   getNumColumnBreaks,   getNumConditionalFormattings,   getNumMergedRegions,   getNumRecords,   getNumRowBreaks,   getPaneInformation,   getPassword,   getPreOffset,   getPrintGridlines,   getPrintSetup,   getProtect,   getRecords,   getRow,   getRowBreaks,   getSelection,   getSize,   getTopRow,   getUncalced,   getWindowTwo,   getXFIndexForColAt,   groupColumnRange,   groupRowRange,   isColumnBroken,   isColumnHidden,   isDisplayFormulas,   isDisplayGridlines,   isDisplayRowColHeadings,   isGridsPrinted,   isProtected,   isRowBroken,   preSerialize,   protectSheet,   removeColumnBreak,   removeConditionalFormatting,   removeMergedRegion,   removeRow,   removeRowBreak,   removeValueRecord,   replaceValueRecord,   serialize,   setActiveCellCol,   setActiveCellRow,   setColumn,   setColumn,   setColumnBreak,   setColumnGroupCollapsed,   setColumnHidden,   setColumnWidth,   setDefaultColumnWidth,   setDefaultRowHeight,   setDimensions,   setDisplayFormulas,   setDisplayGridlines,   setDisplayRowColHeadings,   setFooter,   setGridsPrinted,   setHeader,   setLeftCol,   setLoc,   setMargin,   setPreOffset,   setPrintGridlines,   setPrintSetup,   setRowBreak,   setRowGroupCollapsed,   setSCLRecord,   setSelected,   setSelection,   setTopRow,   setUncalced,   shiftBreaks,   shiftColumnBreaks,   shiftRowBreaks,   unprotectSheet
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.poi.hssf.model.Sheet Detail:
 public int addConditionalFormatting(CFRecordsAggregate cfAggregate) 
 public int addMergedRegion(int rowFrom,
    short colFrom,
    int rowTo,
    short colTo) 
 public  void addRow(RowRecord row) 
    Adds a row record to the sheet

    This method is "loc" sensitive. Meaning you need to set LOC to where you want it to start searching. If you don't know do this: setLoc(getDimsLoc). When adding several rows you can just start at the last one by leaving loc at what this sets it to.

 public  void addValueRecord(int row,
    CellValueRecordInterface col) 
    Adds a value record to the sheet's contained binary records (i.e. LabelSSTRecord or NumberRecord).

    This method is "loc" sensitive. Meaning you need to set LOC to where you want it to start searching. If you don't know do this: setLoc(getDimsLoc). When adding several rows you can just start at the last one by leaving loc at what this sets it to.

 public int aggregateDrawingRecords(DrawingManager2 drawingManager,
    boolean createIfMissing) 
    Finds the DrawingRecord for our sheet, and attaches it to the DrawingManager (which knows about the overall DrawingGroup for our workbook). If requested, will create a new DrawRecord if none currently exist
 public  void checkDimsLoc(Record rec,
    int recloc) 
    in the event the record is a dimensions record, resets both the loc index and dimsloc index
 public Sheet cloneSheet() 
    Clones the low level records of this sheet and returns the new sheet instance. This method is implemented by adding methods for deep cloning to all records that can be added to a sheet. The Record object does not implement cloneable. When adding a new record, implement a public clone method if and only if the record belongs to a sheet.
 protected Record createBOF() 
    creates the BOF record
 public BlankRecord createBlank(int row,
    short col) 
    create a BLANK record (does not add it to the records contained in this sheet)
 protected Record createCalcCount() 
    creates the CalcCount record and sets it to 0x64 (default number of iterations)
 protected Record createCalcMode() 
    creates the CalcMode record and sets it to 1 (automatic formula caculation)
 protected Record createColInfo() 
    creates the ColumnInfo Record and sets it to a default column/width
 protected Record createDefaultColWidth() 
    creates the DefaultColWidth Record and sets it to 8
 protected Record createDefaultRowHeight() 
    creates the DefaultRowHeight Record and sets its options to 0 and rowheight to 0xff
 protected Record createDelta() 
    creates the Delta record and sets it to 0.0010 (default accuracy)
 protected Record createDimensions() 
    creates the Dimensions Record and sets it to bogus values (you should set this yourself or let the high level API do it for you)
 protected Record createEOF() 
    creates the EOF record
 protected Record createFooter() 
    creates the Footer Record and sets it to nothing/0 length
 public FormulaRecord createFormula(int row,
    short col,
    String formula) 
    Attempts to parse the formula into PTGs and create a formula record DOES NOT WORK YET
 public  void createFreezePane(int colSplit,
    int rowSplit,
    int topRow,
    int leftmostColumn) 
    Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
 protected Record createGridset() 
    creates the Gridset record and sets it to true (user has mucked with the gridlines)
 protected Record createGuts() 
    creates the Guts record and sets leftrow/topcol guttter and rowlevelmax/collevelmax to 0
 protected Record createHCenter() 
    creates the HCenter Record and sets it to false (don't horizontally center)
 protected Record createHeader() 
    creates the Header Record and sets it to nothing/0 length
 protected Record createIndex() 
    creates the Index record - not currently used
 protected Record createIteration() 
    creates the Iteration record and sets it to false (don't iteratively calculate formulas)
 public LabelSSTRecord createLabelSST(int row,
    short col,
    int index) 
    Create a LABELSST Record (does not add it to the records contained in this sheet)
 protected Record createMergedCells() 
 public NumberRecord createNumber(int row,
    short col,
    double value) 
    Create a NUMBER Record (does not add it to the records contained in this sheet)
 protected ObjectProtectRecord createObjectProtect() 
    creates an ObjectProtect record with protect set to false.
 protected PasswordRecord createPassword() 
    creates a Password record with password set to 00.
 protected Record createPrintGridlines() 
    creates the PrintGridlines record and sets it to false (that makes for ugly sheets). As far as I can tell this does the same thing as the GridsetRecord
 protected Record createPrintHeaders() 
    creates the PrintHeaders record and sets it to false (we don't create headers yet so why print them)
 protected Record createPrintSetup() 
    creates the PrintSetup Record and sets it to defaults and marks it invalid
 protected Record createProtect() 
    creates a Protect record with protect set to false.
 protected Record createRefMode() 
    creates the RefMode record and sets it to A1 Mode (default reference mode)
 public RowRecord createRow(int row) 
    Create a row record. (does not add it to the records contained in this sheet)
 protected Record createSaveRecalc() 
    creates the SaveRecalc record and sets it to true (recalculate before saving)
 protected ScenarioProtectRecord createScenarioProtect() 
    creates a ScenarioProtect record with protect set to false.
 protected Record createSelection() 
    Creates the Selection record and sets it to nothing selected
 public static Sheet createSheet() 
    Creates a sheet with all the usual records minus values and the "index" record (not required). Sets the location pointer to where the first value records should go. Use this to create a sheet from "scratch".
 public static Sheet createSheet(List records,
    int sheetnum) 
    read support (offset = 0) Same as createSheet(Record[] recs, int, int) only the record offset is assumed to be 0.
 public static Sheet createSheet(List recs,
    int sheetnum,
    int offset) 
    read support (offset used as starting point for search) for low level API. Pass in an array of Record objects, the sheet number (0 based) and a record offset (should be the location of the sheets BOF record). A Sheet object is constructed and passed back with all of its initialization set to the passed in records and references to those records held. This function is normally called via Workbook.
 public  void createSplitPane(int xSplitPos,
    int ySplitPos,
    int topRow,
    int leftmostColumn,
    int activePane) 
    Creates a split pane. Any existing freezepane or split pane is overwritten.
 protected Record createVCenter() 
    creates the VCenter Record and sets it to false (don't horizontally center)
 protected Record createWSBool() 
    creates the WSBoolRecord and sets its values to defaults
 protected WindowTwoRecord createWindowTwo() 
    creates the WindowTwo Record and sets it to:

    options = 0x6b6

    toprow = 0

    leftcol = 0

    headercolor = 0x40

    pagebreakzoom = 0x0

    normalzoom = 0x0

 public Record findFirstRecordBySid(short sid) 
    Returns the first occurance of a record matching a particular sid.
 public int findFirstRecordLocBySid(short sid) 
    Finds the first occurance of a record matching a particular sid and returns it's position.
 public short getActiveCellCol() 
    Returns the active column
 public int getActiveCellRow() 
    Returns the active row
 public CFRecordsAggregate getCFRecordsAggregateAt(int index) 
 public Iterator getColumnBreaks() 
    Returns all the column page breaks
 public short getColumnWidth(short column) 
    get the width of a given column in units of 1/256th of a character width
 public short getDefaultColumnWidth() 
    get the default column width for the sheet (if the columns do not define their own width)
 public short getDefaultRowHeight() 
    get the default row height for the sheet (if the rows do not define their own height)
 public int getDimsLoc() 
    get the location of the DimensionsRecord (which is the last record before the value section)
 public int getEofLoc() 
 public FooterRecord getFooter() 
    Returns the FooterRecord.
 public GridsetRecord getGridsetRecord() 
    Gets the gridset record for this sheet.
 public HeaderRecord getHeader() 
    Returns the HeaderRecord.
 public short getLeftCol() 
 public int getLoc() 
    Returns the location pointer to the first record to look for when adding rows/values
 public double getMargin(short margin) 
    Gets the size of the margin in inches.
 protected Margin[] getMargins() 
    Returns the array of margins. If not created, will create.
 public MergeCellsRecord.MergedRegion getMergedRegionAt(int index) 
 public RowRecord getNextRow() 
    get the NEXT RowRecord (from LOC). The first record that is a Row record (starting at LOC) will be returned.

    This method is "loc" sensitive. Meaning you need to set LOC to where you want it to start searching. If you don't know do this: setLoc(getDimsLoc). When adding several rows you can just start at the last one by leaving loc at what this sets it to. For this method, set loc to dimsloc to start with. subsequent calls will return rows in (physical) sequence or NULL when you get to the end.

 public CellValueRecordInterface getNextValueRecord() 
    get the NEXT value record (from LOC). The first record that is a value record (starting at LOC) will be returned.

    This method is "loc" sensitive. Meaning you need to set LOC to where you want it to start searching. If you don't know do this: setLoc(getDimsLoc). When adding several rows you can just start at the last one by leaving loc at what this sets it to. For this method, set loc to dimsloc to start with, subsequent calls will return values in (physical) sequence or NULL when you get to the end.

 public int getNumColumnBreaks() 
    Returns the number of column page breaks
 public int getNumConditionalFormattings() 
 public int getNumMergedRegions() 
 public int getNumRecords() 
    Returns the number of low level binary records in this sheet. This adjusts things for the so called AgregateRecords.
 public int getNumRowBreaks() 
    Returns the number of row page breaks
 public PaneInformation getPaneInformation() 
    Returns the information regarding the currently configured pane (split or freeze).
 public PasswordRecord getPassword() 
    Returns the PasswordRecord. If one is not contained in the sheet, then one is created.
 public int getPreOffset() 
    get the preoffset when using DBCELL records (currently unused) - this is the position of this sheet within the whole file.
 public PrintGridlinesRecord getPrintGridlines() 
    Returns the PrintGridlinesRecord.
 public PrintSetupRecord getPrintSetup() 
    Returns the PrintSetupRecord.
 public ProtectRecord getProtect() 
    Returns the ProtectRecord. If one is not contained in the sheet, then one is created.
 public List getRecords() 
 public RowRecord getRow(int rownum) 
    get the NEXT (from LOC) RowRecord where rownumber matches the given rownum. The first record that is a Row record (starting at LOC) that has the same rownum as the given rownum will be returned.

    This method is "loc" sensitive. Meaning you need to set LOC to where you want it to start searching. If you don't know do this: setLoc(getDimsLoc). When adding several rows you can just start at the last one by leaving loc at what this sets it to. For this method, set loc to dimsloc to start with. subsequent calls will return rows in (physical) sequence or NULL when you get to the end.

 public Iterator getRowBreaks() 
    Returns all the row page breaks
 public SelectionRecord getSelection() 
 public int getSize() 
 public short getTopRow() 
 public boolean getUncalced() 
 public WindowTwoRecord getWindowTwo() 
 public short getXFIndexForColAt(short column) 
    get the index to the ExtendedFormatRecord "associated" with the column at specified 0-based index. (In this case, an ExtendedFormatRecord index is actually associated with a ColumnInfoRecord which spans 1 or more columns)
    Returns the index to the default ExtendedFormatRecord (0xF) if no ColumnInfoRecord exists that includes the column index specified.
 public  void groupColumnRange(short fromColumn,
    short toColumn,
    boolean indent) 
    Creates an outline group for the specified columns.
 public  void groupRowRange(int fromRow,
    int toRow,
    boolean indent) 
 public boolean isColumnBroken(short column) 
    Queries if the specified column has a page break
 public boolean isColumnHidden(short column) 
    Get the hidden property for a given column.
 public boolean isDisplayFormulas() 
    Returns if formulas are displayed.
 public boolean isDisplayGridlines() 
    Returns if gridlines are displayed.
 public boolean isDisplayRowColHeadings() 
    Returns if RowColHeadings are displayed.
 public boolean isGridsPrinted() 
    get whether gridlines are printed.
 public boolean[] isProtected() 
 public boolean isRowBroken(int row) 
    Queries if the specified row has a page break
 public  void preSerialize() 
    Perform any work necessary before the sheet is about to be serialized. For instance the escher aggregates size needs to be calculated before serialization so that the dgg record (which occurs first) can be written.
 public  void protectSheet(String password,
    boolean objects,
    boolean scenarios) 
    protect a spreadsheet with a password (not encypted, just sets protect flags and the password.
 public  void removeColumnBreak(short column) 
    Removes a page break at the indicated column
 public  void removeConditionalFormatting(int index) 
 public  void removeMergedRegion(int index) 
 public  void removeRow(RowRecord row) 
    Removes a row record This method is not loc sensitive, it resets loc to = dimsloc so no worries.
 public  void removeRowBreak(int row) 
    Removes a page break at the indicated row
 public  void removeValueRecord(int row,
    CellValueRecordInterface col) 
    remove a value record from the records array. This method is not loc sensitive, it resets loc to = dimsloc so no worries.
 public  void replaceValueRecord(CellValueRecordInterface newval) 
    replace a value record from the records array. This method is not loc sensitive, it resets loc to = dimsloc so no worries.
 public int serialize(int offset,
    byte[] data) 
    Serializes all records in the sheet into one big byte array. Use this to write the sheet out.
 public  void setActiveCellCol(short col) 
    Sets the active column
 public  void setActiveCellRow(int row) 
    Sets the active row
 public  void setColumn(short column,
    Short width,
    Integer level,
    Boolean hidden,
    Boolean collapsed) 
 public  void setColumn(short column,
    Short xfStyle,
    Short width,
    Integer level,
    Boolean hidden,
    Boolean collapsed) 
 public  void setColumnBreak(short column,
    short fromRow,
    short toRow) 
    Sets a page break at the indicated column
 public  void setColumnGroupCollapsed(short columnNumber,
    boolean collapsed) 
 public  void setColumnHidden(short column,
    boolean hidden) 
    Get the hidden property for a given column.
 public  void setColumnWidth(short column,
    short width) 
    set the width for a given column in 1/256th of a character width units
 public  void setDefaultColumnWidth(short dcw) 
    set the default column width for the sheet (if the columns do not define their own width)
 public  void setDefaultRowHeight(short dch) 
    set the default row height for the sheet (if the rows do not define their own height)
 public  void setDimensions(int firstrow,
    short firstcol,
    int lastrow,
    short lastcol) 
    Per an earlier reported bug in working with Andy Khan's excel read library. This sets the values in the sheet's DimensionsRecord object to be correct. Excel doesn't really care, but we want to play nice with other libraries.
 public  void setDisplayFormulas(boolean show) 
    Sets whether the formulas are shown in a viewer.
 public  void setDisplayGridlines(boolean show) 
    /** Sets whether the gridlines are shown in a viewer.
 public  void setDisplayRowColHeadings(boolean show) 
    Sets whether the RowColHeadings are shown in a viewer.
 public  void setFooter(FooterRecord newFooter) 
    Sets the FooterRecord.
 public  void setGridsPrinted(boolean value) 
    set whether gridlines printed or not.
 public  void setHeader(HeaderRecord newHeader) 
    Sets the HeaderRecord.
 public  void setLeftCol(short leftCol) 
    Sets the left column to show in desktop window pane.
 public  void setLoc(int loc) 
    set the locator for where we should look for the next value record. The algorithm will actually start here and find the correct location so you can set this to 0 and watch performance go down the tubes but it will work. After a value is set this is automatically advanced. Its also set by the create method. So you probably shouldn't mess with this unless you have a compelling reason why or the help for the method you're calling says so. Check the other methods for whether they care about the loc pointer. Many of the "modify" and "remove" methods re-initialize this to "dimsloc" which is the location of the Dimensions Record and presumably the start of the value section (at or around 19 dec).
 public  void setMargin(short margin,
    double size) 
    Sets the size of the margin in inches.
 public  void setPreOffset(int offset) 
    Set the preoffset when using DBCELL records (currently unused) - this is the position of this sheet within the whole file.
 public  void setPrintGridlines(PrintGridlinesRecord newPrintGridlines) 
    Sets the PrintGridlinesRecord.
 public  void setPrintSetup(PrintSetupRecord newPrintSetup)