public class Workbook extends Object implements Model
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.
HSSFWorkbook
Modifier and Type | Field and Description |
---|---|
protected ArrayList |
boundsheets
holds the "boundsheet" records (aka bundlesheet) so that they can have their
reference to their "BOF" marker
|
protected ExternSheetRecord |
externSheet
Holds the Extern Sheet with references to bound sheets
|
protected ArrayList |
formats |
protected ArrayList |
names |
protected int |
numfonts |
protected int |
numxfs |
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.
|
Constructor and Description |
---|
Workbook()
Creates new Workbook with no intitialization --useless right now
|
Modifier and Type | Method and Description |
---|---|
int |
addBSERecord(EscherBSERecord e) |
NameRecord |
addName(NameRecord name)
creates new name
|
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)
|
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 |
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.
|
NameRecord |
createBuiltInName(byte builtInName,
int index)
Generates a NameRecord to represent a built-in region
|
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 |
createDateWindow1904()
creates the DateWindow1904 record with windowing set to 0.
|
void |
createDrawingGroup()
Creates a drawing group record.
|
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 ExternSheetRecord |
createExternSheet()
creates a new extern sheet record
|
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
|
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.
|
protected Record |
createInterfaceEnd()
creates the InterfaceEnd record
|
protected Record |
createInterfaceHdr()
creates the InterfaceHdr record
|
protected Record |
createMMS()
creates an MMS record
|
NameRecord |
createName()
creates new name
|
FontRecord |
createNewFont()
creates a new font record and adds it to the "font table".
|
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.
|
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(List recs)
read support for low level
API.
|
protected Record |
createWriteAccess()
creates the WriteAccess record containing the logged in user's name
|
boolean |
doesContainsSheetName(String name,
int excludeSheetIdx)
Determines whether a workbook contains the privided sheet name.
|
Record |
findFirstRecordBySid(short sid)
Returns the first occurance of a record matching a particular sid.
|
int |
findFirstRecordLocBySid(short sid)
Returns the index of a record matching a particular sid.
|
Record |
findNextRecordBySid(short sid,
int pos)
Returns the next occurance of a record matching a particular sid.
|
String |
findSheetNameFromExternSheet(short num)
finds the sheet name by his extern sheet index
|
BackupRecord |
getBackupRecord()
Returns the position of the backup record.
|
EscherBSERecord |
getBSERecord(int pictureIndex) |
PaletteRecord |
getCustomPalette()
Returns the custom palette in use for this workbook; if a custom palette record
does not exist, then it is created.
|
DrawingManager2 |
getDrawingManager() |
ExtendedFormatRecord |
getExFormatAt(int index)
gets the ExtendedFormatRecord at the given 0-based index
|
FileSharingRecord |
getFileSharing() |
FontRecord |
getFontRecordAt(int idx)
gets the font record at the given index in the font table.
|
short |
getFormat(String format,
boolean createIfNotFound)
Returns a format index that matches the passed in format.
|
ArrayList |
getFormats()
Returns the list of FormatRecords in the workbook.
|
NameRecord |
getNameRecord(int index)
gets the name record
|
int |
getNumberOfFontRecords()
gets the number of font records
|
int |
getNumExFormats()
get the number of ExtendedFormat records contained in this workbook.
|
int |
getNumNames()
gets the total number of names
|
int |
getNumRecords() |
int |
getNumSheets()
returns the number of boundsheet objects contained in this workbook.
|
List |
getRecords() |
int |
getSheetIndex(String name)
get the sheet's index
|
int |
getSheetIndexFromExternSheetIndex(int externSheetNumber)
Finds the sheet index for a particular external sheet number.
|
String |
getSheetName(int sheetnum)
gets the name for a given sheet.
|
SheetReferences |
getSheetReferences() |
int |
getSize() |
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
|
UnicodeString |
getSSTString(int str)
given an index into the SST table, this function returns the corresponding String value
|
WindowOneRecord |
getWindowOne() |
WriteAccessRecord |
getWriteAccess() |
WriteProtectRecord |
getWriteProtect() |
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....
|
boolean |
isUsing1904DateWindowing()
Whether date windowing is based on 1/2/1904 or 1/1/1900.
|
void |
removeBuiltinRecord(byte name,
int sheetIndex)
Removes the specified Builtin NameRecord that matches the name and index
|
void |
removeName(int namenum)
removes the name
|
void |
removeSheet(int sheetnum) |
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,
String sheetname)
sets the name for a given sheet.
|
void |
setSheetName(int sheetnum,
String sheetname,
short encoding)
Deprecated.
3-Jan-06 Simply use setSheetNam e(int sheetnum, String sheetname)
|
void |
setSheetOrder(String sheetname,
int pos)
sets the order of appearance for a given sheet.
|
void |
unwriteProtectWorkbook()
removes the write protect flag
|
void |
writeProtectWorkbook(String password,
String username)
protect a workbook with a password (not encypted, just sets writeprotect
flags and the password.
|
protected WorkbookRecordList records
protected SSTRecord sst
protected ExternSheetRecord externSheet
protected ArrayList boundsheets
protected ArrayList formats
protected ArrayList names
protected int numxfs
protected int numfonts
public Workbook()
createWorkbook(List)
public static Workbook createWorkbook(List recs)
recs
- an array of Record objectspublic static Workbook createWorkbook()
public NameRecord getSpecificBuiltinRecord(byte name, int sheetIndex)
name
- byte representation of the builtin name to matchsheetIndex
- Index to matchpublic void removeBuiltinRecord(byte name, int sheetIndex)
name
- byte representation of the builtin to matchsheetIndex
- zero-based sheet referencepublic int getNumRecords()
public FontRecord getFontRecordAt(int idx)
idx
- the index to look at (0 or greater but NOT 4)public FontRecord createNewFont()
public int getNumberOfFontRecords()
public void setSheetBof(int sheetnum, int pos)
sheetnum
- the number of the sheet to set the positing of the bof forpos
- the actual bof positionpublic BackupRecord getBackupRecord()
public void setSheetName(int sheetnum, String sheetname)
sheetnum
- the sheet number (0 based)sheetname
- the name for the sheetpublic boolean doesContainsSheetName(String name, int excludeSheetIdx)
name
- the name to testexcludeSheetIdx
- the sheet to exclude from the check or -1 to include all sheets in the check.public void setSheetName(int sheetnum, String sheetname, short encoding)
sheetnum
- the sheet number (0 based)sheetname
- the name for the sheetpublic void setSheetOrder(String sheetname, int pos)
sheetname
- the name of the sheet to reorderpos
- the position that we want to insert the sheet into (0 based)public String getSheetName(int sheetnum)
sheetnum
- the sheet number (0 based)public int getSheetIndex(String name)
name
- sheet namepublic void removeSheet(int sheetnum)
public int getNumSheets()
public int getNumExFormats()
public ExtendedFormatRecord getExFormatAt(int index)
index
- of the Extended format record (0-based)public ExtendedFormatRecord createCellXF()
public int addSSTString(UnicodeString string)
string
- the string to be added to the SSTRecordpublic UnicodeString getSSTString(int str)
public void insertSST()
createSST()
,
SSTRecord
public int serialize(int offset, byte[] data)
offset
- of the data to be writtendata
- array of bytes to write this topublic int getSize()
protected Record createBOF()
protected Record createInterfaceHdr()
InterfaceHdrRecord
,
Record
protected Record createMMS()
protected Record createInterfaceEnd()
InterfaceEndRecord
,
Record
protected Record createWriteAccess()
WriteAccessRecord
,
Record
protected Record createCodepage()
CodepageRecord
,
Record
protected Record createDSF()
protected Record createTabId()
TabIdRecord
,
Record
protected Record createFnGroupCount()
FnGroupCountRecord
,
Record
protected Record createWindowProtect()
WindowProtectRecord
,
Record
protected Record createProtect()
ProtectRecord
,
Record
protected Record createPassword()
PasswordRecord
,
Record
protected Record createProtectionRev4()
ProtectionRev4Record
,
Record
protected Record createPasswordRev4()
PasswordRev4Record
,
Record
protected Record createWindowOne()
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
WindowOneRecord
,
Record
protected Record createBackup()
BackupRecord
,
Record
protected Record createHideObj()
HideObjRecord
,
Record
protected Record createDateWindow1904()
DateWindow1904Record
,
Record
protected Record createPrecision()
PrecisionRecord
,
Record
protected Record createRefreshAll()
RefreshAllRecord
,
Record
protected Record createBookBool()
BookBoolRecord
,
Record
protected Record createFont()
fontheight = 0xc8
attributes = 0x0
color palette index = 0x7fff
bold weight = 0x190
Font Name Length = 5
Font Name = Arial
FontRecord
,
Record
protected Record createFormat(int id)
id
- the number of the format record to create (meaning its position in
a file as M$ Excel would create it.)FormatRecord
,
Record
protected Record createExtendedFormat(int id)
id
- the number of the extended format record to create (meaning its position in
a file as MS Excel would create it.)ExtendedFormatRecord
,
Record
protected ExtendedFormatRecord createExtendedFormat()
protected Record createStyle(int id)
id
- the number of the style record to create (meaning its position in
a file as MS Excel would create it.StyleRecord
,
Record
protected PaletteRecord createPalette()
PaletteRecord
protected Record createUseSelFS()
UseSelFSRecord
,
Record
protected Record createBoundSheet(int id)
id
- either sheet 0,1 or 2.BoundSheetRecord
,
Record
protected Record createCountry()
CountryRecord
,
Record
protected Record createSST()
protected Record createExtendedSST()
ExtSSTRecord
,
Record
protected Record createEOF()
public SheetReferences getSheetReferences()
public String findSheetNameFromExternSheet(short num)
num
- extern sheet indexpublic int getSheetIndexFromExternSheetIndex(int externSheetNumber)
externSheetNumber
- The external sheet number to convertpublic short checkExternSheet(int sheetNumber)
sheetNumber
- sheet numberpublic int getNumNames()
public NameRecord getNameRecord(int index)
index
- name indexpublic NameRecord createName()
public NameRecord addName(NameRecord name)
public NameRecord createBuiltInName(byte builtInName, int index)
public void removeName(int namenum)
namenum
- name indexprotected ExternSheetRecord createExternSheet()
public short getFormat(String format, boolean createIfNotFound)
format
- the format stringcreateIfNotFound
- creates a new format if format not foundpublic ArrayList getFormats()
public short createFormat(String format)
format
- the format stringFormatRecord
,
Record
public Record findFirstRecordBySid(short sid)
public int findFirstRecordLocBySid(short sid)
sid
- The sid of the record to matchpublic Record findNextRecordBySid(short sid, int pos)
public List getRecords()
public boolean isUsing1904DateWindowing()
public PaletteRecord getCustomPalette()
public void createDrawingGroup()
public WindowOneRecord getWindowOne()
public EscherBSERecord getBSERecord(int pictureIndex)
public int addBSERecord(EscherBSERecord e)
public DrawingManager2 getDrawingManager()
public WriteProtectRecord getWriteProtect()
public WriteAccessRecord getWriteAccess()
public FileSharingRecord getFileSharing()
public void writeProtectWorkbook(String password, String username)
password
- to setpublic void unwriteProtectWorkbook()
Copyright © 2014 Open Microscopy Environment