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

All Implemented Interfaces:
    Model

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.

Field Summary
protected  WorkbookRecordList 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  ArrayList boundsheets    holds the "boundsheet" records (aka bundlesheet) so that they can have their reference to their "BOF" marker 
protected  ArrayList formats     
protected  ArrayList hyperlinks     
protected  int numxfs     
protected  int numfonts     
Constructor:
 public Workbook() 
Method from org.apache.poi.hssf.model.Workbook Summary:
addBSERecord,   addName,   addSSTString,   checkExternSheet,   createBOF,   createBackup,   createBookBool,   createBoundSheet,   createBuiltInName,   createCellXF,   createCodepage,   createCountry,   createDSF,   createDateWindow1904,   createDrawingGroup,   createEOF,   createExtendedFormat,   createExtendedFormat,   createExtendedSST,   createFnGroupCount,   createFont,   createFormat,   createFormat,   createHideObj,   createInterfaceEnd,   createInterfaceHdr,   createMMS,   createName,   createNewFont,   createPalette,   createPassword,   createPasswordRev4,   createPrecision,   createProtect,   createProtectionRev4,   createRefreshAll,   createSST,   createStyle,   createTabId,   createUseSelFS,   createWindowOne,   createWindowProtect,   createWorkbook,   createWorkbook,   createWriteAccess,   doesContainsSheetName,   findDrawingGroup,   findFirstRecordBySid,   findFirstRecordLocBySid,   findNextRecordBySid,   findSheetNameFromExternSheet,   getBSERecord,   getBackupRecord,   getCustomPalette,   getDrawingManager,   getExFormatAt,   getFileSharing,   getFontRecordAt,   getFormat,   getFormats,   getHyperlinks,   getNameRecord,   getNumExFormats,   getNumNames,   getNumRecords,   getNumSheets,   getNumberOfFontRecords,   getRecords,   getSSTString,   getSheetIndex,   getSheetIndexFromExternSheetIndex,   getSheetName,   getSheetReferences,   getSize,   getSpecificBuiltinRecord,   getWindowOne,   getWriteAccess,   getWriteProtect,   insertSST,   isSheetHidden,   isUsing1904DateWindowing,   isWriteProtected,   removeBuiltinRecord,   removeName,   removeSheet,   resolveNameXText,   serialize,   setSheetBof,   setSheetHidden,   setSheetName,   setSheetName,   setSheetOrder,   unwriteProtectWorkbook,   writeProtectWorkbook
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.poi.hssf.model.Workbook Detail:
 public int addBSERecord(EscherBSERecord e) 
 public NameRecord addName(NameRecord name) 
    creates new name
 public int addSSTString(UnicodeString 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)
 public short checkExternSheet(int sheetNumber) 
    returns the extern sheet number for specific sheet number , if this sheet doesn't exist in extern sheet , add it
 protected Record createBOF() 
    creates the BOF record
 protected Record createBackup() 
    creates the Backup record with backup set to 0. (loose the data, who cares)
 protected Record createBookBool() 
    creates the BookBool record with saveLinkValues set to 0. (don't save link values)
 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.
 public NameRecord createBuiltInName(byte builtInName,
    int index) 
    Generates a NameRecord to represent a built-in region
 public 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 country set to 1 and current country set to 7 in case of russian locale ("ru_RU") and 1 otherwise
 protected Record createDSF() 
    creates the DSF record containing a 0 since HSSF can't even create Dual Stream Files
 protected Record createDateWindow1904() 
    creates the DateWindow1904 record with windowing set to 0. (don't window)
 public  void createDrawingGroup() 
    Creates a primary drawing group record. If it already exists then it's modified.
 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. 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
 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:

    fontheight = 0xc8

    attributes = 0x0

    color palette index = 0x7fff

    bold weight = 0x190

    Font Name Length = 5

    Font Name = Arial

 protected Record createFormat(int id) 
    Creates a FormatRecord object
 public short createFormat(String format) 
    Creates a FormatRecord, inserts it, and returns the index code.
 protected Record createHideObj() 
    creates the HideObj record with hide object set to 0. (don't hide)
 protected Record createInterfaceEnd() 
    creates the InterfaceEnd record
 protected Record createInterfaceHdr() 
    creates the InterfaceHdr record
 protected Record createMMS() 
    creates an MMS record
 public NameRecord createName() 
    creates new name
 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)
 protected PaletteRecord createPalette() 
    Creates a palette record initialized to the default palette
 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. (full precision)
 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. (refresh all calcs)
 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. This release of HSSF always has the default three sheets, no less, no more.
 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:

    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

 protected Record createWindowProtect() 
    creates the WindowProtect record with protect set to false.
 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.
 public static Workbook createWorkbook(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.
 protected Record createWriteAccess() 
    creates the WriteAccess record containing the logged in user's name
 public boolean doesContainsSheetName(String name,
    int excludeSheetIdx) 
    Determines whether a workbook contains the provided sheet name.
 public  void findDrawingGroup() 
    Finds the primary drawing group, if one already exists
 public Record findFirstRecordBySid(short sid) 
    Returns the first occurance of a record matching a particular sid.
 public int findFirstRecordLocBySid(short sid) 
    Returns the index of a record matching a particular sid.
 public Record findNextRecordBySid(short sid,
    int pos) 
    Returns the next occurance of a record matching a particular sid.
 public String findSheetNameFromExternSheet(short num) 
    finds the sheet name by his extern sheet index
 public EscherBSERecord getBSERecord(int pictureIndex) 
 public BackupRecord getBackupRecord() 
    Returns the position of the backup record.
 public PaletteRecord getCustomPalette() 
    Returns the custom palette in use for this workbook; if a custom palette record does not exist, then it is created.
 public DrawingManager2 getDrawingManager() 
 public ExtendedFormatRecord getExFormatAt(int index) 
    gets the ExtendedFormatRecord at the given 0-based index
 public FileSharingRecord getFileSharing() 
 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)
 public short getFormat(String format,
    boolean createIfNotFound) 
    Returns a format index that matches the passed in format. It does not tie into HSSFDataFormat.
 public ArrayList getFormats() 
    Returns the list of FormatRecords in the workbook.
 public List getHyperlinks() 
 public NameRecord getNameRecord(int index) 
    gets the name record
 public int getNumExFormats() 
    get the number of ExtendedFormat records contained in this workbook.
 public int getNumNames() 
    gets the total number of names
 public int getNumRecords() 
 public int getNumSheets() 
    returns the number of boundsheet objects contained in this workbook.
 public int getNumberOfFontRecords() 
    gets the number of font records
 public List getRecords() 
 public UnicodeString getSSTString(int str) 
    given an index into the SST table, this function returns the corresponding String value
 public int getSheetIndex(String name) 
    get the sheet's index
 public int getSheetIndexFromExternSheetIndex(int externSheetNumber) 
    Finds the sheet index for a particular external sheet number.
 public String getSheetName(int sheetnum) 
    gets the name for a given sheet.
 public SheetReferences getSheetReferences() 
 public int getSize() 
 public NameRecord getSpecificBuiltinRecord(byte name,
    int sheetIndex) 
    Retrieves the Builtin NameRecord that matches the name and index There shouldn't be too many names to make the sequential search too slow
 public WindowOneRecord getWindowOne() 
 public WriteAccessRecord getWriteAccess() 
 public WriteProtectRecord getWriteProtect() 
 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....
 public boolean isSheetHidden(int sheetnum) 
    gets the hidden flag for a given sheet.
 public boolean isUsing1904DateWindowing() 
    Whether date windowing is based on 1/2/1904 or 1/1/1900. Some versions of Excel (Mac) can save workbooks using 1904 date windowing.
 public boolean isWriteProtected() 
    is the workbook protected with a password (not encrypted)?
 public  void removeBuiltinRecord(byte name,
    int sheetIndex) 
    Removes the specified Builtin NameRecord that matches the name and index
 public  void removeName(int namenum) 
    removes the name
 public  void removeSheet(int sheetnum) 
 public String resolveNameXText(int refIndex,
    int definedNameIndex) 
 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.
 public  void setSheetBof(int sheetnum,
    int pos) 
    Sets the BOF for a given sheet
 public  void setSheetHidden(int sheetnum,
    boolean hidden) 
    Hide or unhide a sheet
 public  void setSheetName(int sheetnum,
    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
 public  void setSheetName(int sheetnum,
    String sheetname,
    short encoding) 
Deprecated! 3-Jan-06 - Simply use setSheetNam e(int sheetnum, String sheetname)

    sets the name for a given sheet forcing the encoding. This is STILL A BAD IDEA. Poi now automatically detects unicode
 public  void setSheetOrder(String sheetname,
    int pos) 
    sets the order of appearance for a given sheet.
 public  void unwriteProtectWorkbook() 
    removes the write protect flag
 public  void writeProtectWorkbook(String password,
    String username) 
    protect a workbook with a password (not encypted, just sets writeprotect flags and the password.