org.apache.poi.hssf.model
Class Workbook

java.lang.Object
  |
  +--org.apache.poi.hssf.model.Workbook

public class Workbook
extends java.lang.Object

Workbook Low level model implementation of a Workbook. Provides creational methods for settings and objects contained in the workbook object.

This file contains the low level binary records starting at the workbook's BOF and ending with the workbook's EOF. Use HSSFWorkbook 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.

Version:
1.0-pre
Author:
Andrew C. Oliver (acoliver at apache dot org), Glen Stampoultzis (glens at apache.org)
See Also:
HSSFWorkbook

Field Summary
protected  java.util.ArrayList boundsheets
          holds the "boundsheet" records (aka bundlesheet) so that they can have their reference to their "BOF" marker
protected  int bspos
           
protected  int fontpos
           
protected  int numfonts
           
protected  int numxfs
           
protected  java.util.ArrayList records
          this contains the Worksheet record objects
protected  SSTRecord sst
          this contains a reference to the SSTRecord so that new stings can be added to it.
protected  int tabpos
           
protected  int xfpos
           
 
Constructor Summary
Workbook()
          Creates new Workbook with no intitialization --useless right now
 
Method Summary
 int addSSTString(java.lang.String string)
          Adds a string to the SST table and returns its index (if its a duplicate just returns its index and update the counts) ASSUMES compressed unicode (meaning 8bit)
 int addSSTString(java.lang.String string, boolean use16bits)
          Adds a string to the SST table and returns its index (if its a duplicate just returns its index and update the counts)
protected  Record createBackup()
          creates the Backup record with backup set to 0.
protected  Record createBOF()
          creates the BOF record
protected  Record createBookBool()
          creates the BookBool record with saveLinkValues set to 0.
protected  Record createBoundSheet(int id)
          create a "bound sheet" or "bundlesheet" (depending who you ask) record Always sets the sheet's bof to 0.
 ExtendedFormatRecord createCellXF()
          creates a new Cell-type Extneded Format Record and adds it to the end of ExtendedFormatRecords collection
protected  Record createCodepage()
          creates the Codepage record containing the constant stored in CODEPAGE
protected  Record createCountry()
          Creates the Country record with the default and current country set to 1
protected  Record createDateWindow1904()
          creates the DateWindow1904 record with windowing set to 0.
protected  Record createDSF()
          creates the DSF record containing a 0 since HSSF can't even create Dual Stream Files
protected  Record createEOF()
          creates the EOF record
protected  ExtendedFormatRecord createExtendedFormat()
          creates an default cell type ExtendedFormatRecord object.
protected  Record createExtendedFormat(int id)
          Creates an ExtendedFormatRecord object
protected  Record createExtendedSST()
          Creates the ExtendedSST record with numstrings per bucket set to 0x8.
protected  Record createFnGroupCount()
          creates the FnGroupCount record containing the Magic number constant of 14.
protected  Record createFont()
          creates a Font record with the following magic values:
protected  Record createFormat(int id)
          Creates a FormatRecord object
protected  Record createHideObj()
          creates the HideObj record with hide object set to 0.
protected  Record createInterfaceEnd()
          creates the InterfaceEnd record
protected  Record createInterfaceHdr()
          creates the InterfaceHdr record
protected  Record createMMS()
          creates an MMS record
 FontRecord createNewFont()
          creates a new font record and adds it to the "font table".
protected  Record createPassword()
          creates the Password record with password set to 0.
protected  Record createPasswordRev4()
          creates the PasswordRev4 record with password set to 0.
protected  Record createPrecision()
          creates the Precision record with precision set to true.
protected  Record createProtect()
          creates the Protect record with protect set to false.
protected  Record createProtectionRev4()
          creates the ProtectionRev4 record with protect set to false.
protected  Record createRefreshAll()
          creates the RefreshAll record with refreshAll set to true.
protected  Record createSST()
          Creates the SST record with no strings and the unique/num string set to 0
protected  Record createStyle(int id)
          Creates a StyleRecord object
protected  Record createTabId()
          creates the TabId record containing an array of 0,1,2.
protected  Record createUseSelFS()
          Creates the UseSelFS object with the use natural language flag set to 0 (false)
protected  Record createWindowOne()
          creates the WindowOne record with the following magic values:
protected  Record createWindowProtect()
          creates the WindowProtect record with protect set to false.
static Workbook createWorkbook()
          Creates an empty workbook object with three blank sheets and all the empty fields.
static Workbook createWorkbook(java.util.List recs)
          read support for low level API.
protected  Record createWriteAccess()
          creates the WriteAccess record containing the logged in user's name
 Record findFirstRecordBySid(short sid)
          Returns the first occurance of a record matching a particular sid.
 BackupRecord getBackupRecord()
          Returns the position of the backup record.
 ExtendedFormatRecord getExFormatAt(int index)
          gets the ExtendedFormatRecord at the given 0-based index
 FontRecord getFontRecordAt(int idx)
          gets the font record at the given index in the font table.
 int getNumberOfFontRecords()
          gets the number of font records
 int getNumExFormats()
          get the number of ExtendedFormat records contained in this workbook.
 int getNumRecords()
           
 int getNumSheets()
          returns the number of boundsheet objects contained in this workbook.
 java.lang.String getSheetName(int sheetnum)
          gets the name for a given sheet.
 int getSize()
           
 java.lang.String getSSTString(int str)
          given an index into the SST table, this function returns the corresponding String value
 void insertSST()
          use this function to add a Shared String Table to an existing sheet (say generated by a different java api) without an sst....
 void removeSheet(int sheetnum)
           
 byte[] serialize()
          Serializes all records int the worksheet section into a big byte array.
 int serialize(int offset, byte[] data)
          Serializes all records int the worksheet section into a big byte array.
 void setSheetBof(int sheetnum, int pos)
          Sets the BOF for a given sheet
 void setSheetName(int sheetnum, java.lang.String sheetname)
          sets the name for a given sheet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

records

protected java.util.ArrayList records
this contains the Worksheet record objects

sst

protected SSTRecord sst
this contains a reference to the SSTRecord so that new stings can be added to it.

boundsheets

protected java.util.ArrayList boundsheets
holds the "boundsheet" records (aka bundlesheet) so that they can have their reference to their "BOF" marker

bspos

protected int bspos

tabpos

protected int tabpos

fontpos

protected int fontpos

numfonts

protected int numfonts

xfpos

protected int xfpos

numxfs

protected int numxfs
Constructor Detail

Workbook

public Workbook()
Creates new Workbook with no intitialization --useless right now
See Also:
createWorkbook(List)
Method Detail

createWorkbook

public static Workbook createWorkbook(java.util.List recs)
read support for low level API. Pass in an array of Record objects, A Workbook object is constructed and passed back with all of its initialization set to the passed in records and references to those records held. Unlike Sheet workbook does not use an offset (its assumed to be 0) since its first in a file. If you need an offset then construct a new array with a 0 offset or write your own ;-p.
Parameters:
recs - an array of Record objects
Returns:
Workbook object

createWorkbook

public static Workbook createWorkbook()
Creates an empty workbook object with three blank sheets and all the empty fields. Use this to create a workbook from scratch.

getNumRecords

public int getNumRecords()

getFontRecordAt

public FontRecord getFontRecordAt(int idx)
gets the font record at the given index in the font table. Remember "There is No Four" (someone at M$ must have gone to Rocky Horror one too many times)
Parameters:
idx - the index to look at (0 or greater but NOT 4)
Returns:
FontRecord located at the given index

createNewFont

public FontRecord createNewFont()
creates a new font record and adds it to the "font table". This causes the boundsheets to move down one, extended formats to move down (so this function moves those pointers as well)
Returns:
FontRecord that was just created

getNumberOfFontRecords

public int getNumberOfFontRecords()
gets the number of font records
Returns:
number of font records in the "font table"

setSheetBof

public void setSheetBof(int sheetnum,
                        int pos)
Sets the BOF for a given sheet
Parameters:
sheetnum - the number of the sheet to set the positing of the bof for
pos - the actual bof position

getBackupRecord

public BackupRecord getBackupRecord()
Returns the position of the backup record.

setSheetName

public void setSheetName(int sheetnum,
                         java.lang.String sheetname)
sets the name for a given sheet. If the boundsheet record doesn't exist and its only one more than we have, go ahead and create it. If its > 1 more than we have, except
Parameters:
sheetnum - the sheet number (0 based)
sheetname - the name for the sheet

getSheetName

public java.lang.String getSheetName(int sheetnum)
gets the name for a given sheet.
Parameters:
sheetnum - the sheet number (0 based)
Returns:
sheetname the name for the sheet

removeSheet

public void removeSheet(int sheetnum)

getNumSheets

public int getNumSheets()
returns the number of boundsheet objects contained in this workbook.
Returns:
number of BoundSheet records

getNumExFormats

public int getNumExFormats()
get the number of ExtendedFormat records contained in this workbook.
Returns:
int count of ExtendedFormat records

getExFormatAt

public ExtendedFormatRecord getExFormatAt(int index)
gets the ExtendedFormatRecord at the given 0-based index
Parameters:
index - of the Extended format record (0-based)
Returns:
ExtendedFormatRecord at the given index

createCellXF

public ExtendedFormatRecord createCellXF()
creates a new Cell-type Extneded Format Record and adds it to the end of ExtendedFormatRecords collection
Returns:
ExtendedFormatRecord that was created

addSSTString

public int addSSTString(java.lang.String string,
                        boolean use16bits)
Adds a string to the SST table and returns its index (if its a duplicate just returns its index and update the counts)
Parameters:
string - the string to be added to the SSTRecord
use16bits - whether to use utf 16 or false for compressed unicode
Returns:
index of the string within the SSTRecord

addSSTString

public int addSSTString(java.lang.String string)
Adds a string to the SST table and returns its index (if its a duplicate just returns its index and update the counts) ASSUMES compressed unicode (meaning 8bit)
Parameters:
string - the string to be added to the SSTRecord
Returns:
index of the string within the SSTRecord

getSSTString

public java.lang.String getSSTString(int str)
given an index into the SST table, this function returns the corresponding String value
Returns:
String containing the SST String

insertSST

public void insertSST()
use this function to add a Shared String Table to an existing sheet (say generated by a different java api) without an sst....
See Also:
createSST(), SSTRecord

serialize

public byte[] serialize()
Serializes all records int the worksheet section into a big byte array. Use this to write the Workbook out.
Returns:
byte array containing the HSSF-only portions of the POIFS file.

serialize

public int serialize(int offset,
                     byte[] data)
Serializes all records int the worksheet section into a big byte array. Use this to write the Workbook out.
Parameters:
offset - of the data to be written
data - array of bytes to write this to

getSize

public int getSize()

createBOF

protected Record createBOF()
creates the BOF record
Returns:
record containing a BOFRecord
See Also:
BOFRecord, Record

createInterfaceHdr

protected Record createInterfaceHdr()
creates the InterfaceHdr record
Returns:
record containing a InterfaceHdrRecord
See Also:
InterfaceHdrRecord, Record

createMMS

protected Record createMMS()
creates an MMS record
Returns:
record containing a MMSRecord
See Also:
MMSRecord, Record

createInterfaceEnd

protected Record createInterfaceEnd()
creates the InterfaceEnd record
Returns:
record containing a InterfaceEndRecord
See Also:
InterfaceEndRecord, Record

createWriteAccess

protected Record createWriteAccess()
creates the WriteAccess record containing the logged in user's name
Returns:
record containing a WriteAccessRecord
See Also:
WriteAccessRecord, Record

createCodepage

protected Record createCodepage()
creates the Codepage record containing the constant stored in CODEPAGE
Returns:
record containing a CodepageRecord
See Also:
CodepageRecord, Record

createDSF

protected Record createDSF()
creates the DSF record containing a 0 since HSSF can't even create Dual Stream Files
Returns:
record containing a DSFRecord
See Also:
DSFRecord, Record

createTabId

protected Record createTabId()
creates the TabId record containing an array of 0,1,2. This release of HSSF always has the default three sheets, no less, no more.
Returns:
record containing a TabIdRecord
See Also:
TabIdRecord, Record

createFnGroupCount

protected Record createFnGroupCount()
creates the FnGroupCount record containing the Magic number constant of 14.
Returns:
record containing a FnGroupCountRecord
See Also:
FnGroupCountRecord, Record

createWindowProtect

protected Record createWindowProtect()
creates the WindowProtect record with protect set to false.
Returns:
record containing a WindowProtectRecord
See Also:
WindowProtectRecord, Record

createProtect

protected Record createProtect()
creates the Protect record with protect set to false.
Returns:
record containing a ProtectRecord
See Also:
ProtectRecord, Record

createPassword

protected Record createPassword()
creates the Password record with password set to 0.
Returns:
record containing a PasswordRecord
See Also:
PasswordRecord, Record

createProtectionRev4

protected Record createProtectionRev4()
creates the ProtectionRev4 record with protect set to false.
Returns:
record containing a ProtectionRev4Record
See Also:
ProtectionRev4Record, Record

createPasswordRev4

protected Record createPasswordRev4()
creates the PasswordRev4 record with password set to 0.
Returns:
record containing a PasswordRev4Record
See Also:
PasswordRev4Record, Record

createWindowOne

protected Record createWindowOne()
creates the WindowOne record with the following magic values:

horizontal hold - 0x168

vertical hold - 0x10e

width - 0x3a5c

height - 0x23be

options - 0x38

selected tab - 0

displayed tab - 0

num selected tab- 0

tab width ratio - 0x258

Returns:
record containing a WindowOneRecord
See Also:
WindowOneRecord, Record

createBackup

protected Record createBackup()
creates the Backup record with backup set to 0. (loose the data, who cares)
Returns:
record containing a BackupRecord
See Also:
BackupRecord, Record

createHideObj

protected Record createHideObj()
creates the HideObj record with hide object set to 0. (don't hide)
Returns:
record containing a HideObjRecord
See Also:
HideObjRecord, Record

createDateWindow1904

protected Record createDateWindow1904()
creates the DateWindow1904 record with windowing set to 0. (don't window)
Returns:
record containing a DateWindow1904Record
See Also:
DateWindow1904Record, Record

createPrecision

protected Record createPrecision()
creates the Precision record with precision set to true. (full precision)
Returns:
record containing a PrecisionRecord
See Also:
PrecisionRecord, Record

createRefreshAll

protected Record createRefreshAll()
creates the RefreshAll record with refreshAll set to true. (refresh all calcs)
Returns:
record containing a RefreshAllRecord
See Also:
RefreshAllRecord, Record

createBookBool

protected Record createBookBool()
creates the BookBool record with saveLinkValues set to 0. (don't save link values)
Returns:
record containing a BookBoolRecord
See Also:
BookBoolRecord, Record

createFont

protected Record createFont()
creates a Font record with the following magic values:

fontheight = 0xc8

attributes = 0x0

color palette index = 0x7fff

bold weight = 0x190

Font Name Length = 5

Font Name = Arial

Returns:
record containing a FontRecord
See Also:
FontRecord, Record

createFormat

protected Record createFormat(int id)
Creates a FormatRecord object
Parameters:
id - the number of the format record to create (meaning its position in a file as M$ Excel would create it.)
Returns:
record containing a FormatRecord
See Also:
FormatRecord, Record

createExtendedFormat

protected Record createExtendedFormat(int id)
Creates an ExtendedFormatRecord object
Parameters:
id - the number of the extended format record to create (meaning its position in a file as MS Excel would create it.)
Returns:
record containing an ExtendedFormatRecord
See Also:
ExtendedFormatRecord, Record

createExtendedFormat

protected ExtendedFormatRecord createExtendedFormat()
creates an default cell type ExtendedFormatRecord object.
Returns:
ExtendedFormatRecord with intial defaults (cell-type)

createStyle

protected Record createStyle(int id)
Creates a StyleRecord object
Parameters:
id - the number of the style record to create (meaning its position in a file as MS Excel would create it.
Returns:
record containing a StyleRecord
See Also:
StyleRecord, Record

createUseSelFS

protected Record createUseSelFS()
Creates the UseSelFS object with the use natural language flag set to 0 (false)
Returns:
record containing a UseSelFSRecord
See Also:
UseSelFSRecord, Record

createBoundSheet

protected Record createBoundSheet(int id)
create a "bound sheet" or "bundlesheet" (depending who you ask) record Always sets the sheet's bof to 0. You'll need to set that yourself.
Parameters:
id - either sheet 0,1 or 2.
Returns:
record containing a BoundSheetRecord
See Also:
BoundSheetRecord, Record

createCountry

protected Record createCountry()
Creates the Country record with the default and current country set to 1
Returns:
record containing a CountryRecord
See Also:
CountryRecord, Record

createSST

protected Record createSST()
Creates the SST record with no strings and the unique/num string set to 0
Returns:
record containing a SSTRecord
See Also:
SSTRecord, Record

createExtendedSST

protected Record createExtendedSST()
Creates the ExtendedSST record with numstrings per bucket set to 0x8. HSSF doesn't yet know what to do with this thing, but we create it with nothing in it hardly just to make Excel happy and our sheets look like Excel's
Returns:
record containing an ExtSSTRecord
See Also:
ExtSSTRecord, Record

createEOF

protected Record createEOF()
creates the EOF record
Returns:
record containing a EOFRecord
See Also:
EOFRecord, Record

findFirstRecordBySid

public Record findFirstRecordBySid(short sid)
Returns the first occurance of a record matching a particular sid.


Copyright © 2002 Apache jakarta-poi project. All Rights Reserved.