@Internal public final class InternalWorkbook extends java.lang.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.
HSSFWorkbook
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
OLD_WORKBOOK_DIR_ENTRY_NAME
Name of older (pre-Excel 97) Workbook streams, which
aren't supported by HSSFWorkbook, only by
OldExcelExtractor |
protected SSTRecord |
sst
this contains a reference to the SSTRecord so that new stings can be added
to it.
|
static java.lang.String[] |
WORKBOOK_DIR_ENTRY_NAMES
Normally, the Workbook will be in a POIFS Stream called
"Workbook".
|
Modifier and Type | Method and Description |
---|---|
int |
addBSERecord(EscherBSERecord e) |
NameRecord |
addName(NameRecord name)
adds a name record
|
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)
|
boolean |
changeExternalReference(java.lang.String oldUrl,
java.lang.String newUrl)
Changes an external referenced file to another file.
|
short |
checkExternSheet(int sheetNumber)
Returns the extern sheet number for specific sheet number.
|
short |
checkExternSheet(int firstSheetNumber,
int lastSheetNumber)
Returns the extern sheet number for specific range of sheets.
|
void |
cloneDrawings(InternalSheet sheet)
Check if the cloned sheet has drawings.
|
NameRecord |
cloneFilter(int filterDbNameIndex,
int newSheetIndex) |
NameRecord |
createBuiltInName(byte builtInName,
int sheetNumber)
Generates a NameRecord to represent a built-in region
|
ExtendedFormatRecord |
createCellXF()
creates a new Cell-type Extended Format Record and adds it to the end of
ExtendedFormatRecords collection
|
void |
createDrawingGroup()
Creates a primary drawing group record.
|
int |
createFormat(java.lang.String formatString)
Creates a FormatRecord, inserts it, and returns the index code.
|
NameRecord |
createName()
creates new name
|
FontRecord |
createNewFont()
creates a new font record and adds it to the "font table".
|
StyleRecord |
createStyleRecord(int xfIndex)
Creates a new StyleRecord, for the given Extended
Format index, and adds it onto the end of the
records collection
|
static InternalWorkbook |
createWorkbook()
Creates an empty workbook object with three blank sheets and all the empty
fields.
|
static InternalWorkbook |
createWorkbook(java.util.List<Record> recs)
read support for low level
API.
|
boolean |
doesContainsSheetName(java.lang.String name,
int excludeSheetIdx)
Determines whether a workbook contains the provided sheet name.
|
DrawingManager2 |
findDrawingGroup()
Finds the primary drawing group, if one already exists
|
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.
|
java.lang.String |
findSheetFirstNameFromExternSheet(int externSheetIndex)
Finds the first sheet name by his extern sheet index
|
java.lang.String |
findSheetLastNameFromExternSheet(int externSheetIndex) |
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
|
EvaluationWorkbook.ExternalName |
getExternalName(int externSheetIndex,
int externNameIndex) |
EvaluationWorkbook.ExternalSheet |
getExternalSheet(int externSheetIndex) |
int |
getExternalSheetIndex(java.lang.String workbookName,
java.lang.String sheetName) |
int |
getExternalSheetIndex(java.lang.String workbookName,
java.lang.String firstSheetName,
java.lang.String lastSheetName) |
FileSharingRecord |
getFileSharing() |
int |
getFirstSheetIndexFromExternSheetIndex(int externSheetNumber)
Finds the (first) sheet index for a particular external sheet number.
|
int |
getFontIndex(FontRecord font)
Retrieves the index of the given font
|
FontRecord |
getFontRecordAt(int idx)
gets the font record at the given index in the font table.
|
short |
getFormat(java.lang.String format,
boolean createIfNotFound)
Returns a format index that matches the passed in format.
|
java.util.List<FormatRecord> |
getFormats()
Returns the list of FormatRecords in the workbook.
|
java.util.List<HyperlinkRecord> |
getHyperlinks() |
int |
getLastSheetIndexFromExternSheetIndex(int externSheetNumber)
Finds the last sheet index for a particular external sheet number,
which may be the same as the first (except for multi-sheet references)
|
NameCommentRecord |
getNameCommentRecord(NameRecord nameRecord)
gets the name comment record
|
NameRecord |
getNameRecord(int index)
gets the name record
|
NameXPtg |
getNameXPtg(java.lang.String name,
int sheetRefIndex,
UDFFinder udf) |
NameXPtg |
getNameXPtg(java.lang.String name,
UDFFinder udf) |
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.
|
RecalcIdRecord |
getRecalcId()
Get or create RecalcIdRecord
|
java.util.List<Record> |
getRecords() |
int |
getSheetIndex(java.lang.String name)
get the sheet's index
|
java.lang.String |
getSheetName(int sheetIndex)
gets the name for a given sheet.
|
SheetVisibility |
getSheetVisibility(int sheetnum)
Gets the hidden flag for a given sheet.
|
int |
getSize() |
NameRecord |
getSpecificBuiltinRecord(byte name,
int sheetNumber)
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
|
StyleRecord |
getStyleRecord(int xfIndex)
Returns the StyleRecord for the given
xfIndex, or null if that ExtendedFormat doesn't
have a Style set.
|
WindowOneRecord |
getWindowOne() |
WorkbookRecordList |
getWorkbookRecordList()
Only for internal calls - code based on this is not supported ...
|
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 |
isSheetHidden(int sheetnum)
Gets the hidden flag for a given sheet.
|
boolean |
isSheetVeryHidden(int sheetnum)
Gets the very hidden flag for a given sheet.
|
boolean |
isUsing1904DateWindowing()
Whether date windowing is based on 1/2/1904 or 1/1/1900.
|
boolean |
isWriteProtected()
is the workbook protected with a password (not encrypted)?
|
int |
linkExternalWorkbook(java.lang.String name,
Workbook externalWorkbook) |
void |
preSerialize()
Perform any work necessary before the workbook is about to be serialized.
|
void |
removeBuiltinRecord(byte name,
int sheetIndex)
Removes the specified Builtin NameRecord that matches the name and index
|
void |
removeExFormatRecord(ExtendedFormatRecord rec)
Removes the given ExtendedFormatRecord record from the
file's list.
|
void |
removeExFormatRecord(int index)
Removes ExtendedFormatRecord record with given index from the
file's list.
|
void |
removeFontRecord(FontRecord rec)
Removes the given font record from the
file's list.
|
void |
removeName(int nameIndex)
removes the name
|
void |
removeSheet(int sheetIndex) |
java.lang.String |
resolveNameXText(int refIndex,
int definedNameIndex) |
int |
serialize(int offset,
byte[] data)
Serializes all records int the worksheet section into a big byte array.
|
void |
setSheetBof(int sheetIndex,
int pos)
Sets the BOF for a given sheet
|
void |
setSheetHidden(int sheetnum,
boolean hidden)
Hide or unhide a sheet
|
void |
setSheetHidden(int sheetnum,
SheetVisibility visibility)
Hide or unhide a sheet.
|
void |
setSheetName(int sheetnum,
java.lang.String sheetname)
sets the name for a given sheet.
|
void |
setSheetOrder(java.lang.String sheetname,
int pos)
sets the order of appearance for a given sheet.
|
void |
unwriteProtectWorkbook()
removes the write protect flag
|
void |
updateNameCommentRecordCache(NameCommentRecord commentRecord)
If a
NameCommentRecord is added or the name it references
is renamed, then this will update the lookup cache for it. |
void |
updateNamesAfterCellShift(FormulaShifter shifter)
Updates named ranges due to moving of cells
|
void |
updateStyleRecord(int oldXf,
int newXf)
Update the StyleRecord to point to the new
given index.
|
void |
writeProtectWorkbook(java.lang.String password,
java.lang.String username)
protect a workbook with a password (not encypted, just sets writeprotect
flags and the password.
|
public static final java.lang.String[] WORKBOOK_DIR_ENTRY_NAMES
public static final java.lang.String OLD_WORKBOOK_DIR_ENTRY_NAME
OldExcelExtractor
protected SSTRecord sst
public static InternalWorkbook createWorkbook(java.util.List<Record> recs)
recs
- an array of Record objectspublic static InternalWorkbook createWorkbook()
public NameRecord getSpecificBuiltinRecord(byte name, int sheetNumber)
name
- byte representation of the builtin name to matchsheetNumber
- 1-based sheet numberpublic 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 int getFontIndex(FontRecord font)
font
- the fontjava.lang.IllegalArgumentException
- if the font index can't be determinedpublic FontRecord createNewFont()
public void removeFontRecord(FontRecord rec)
rec
- the font recordpublic int getNumberOfFontRecords()
public void setSheetBof(int sheetIndex, int pos)
sheetIndex
- the number of the sheet to set the positing of the bof forpos
- the actual bof positionpublic BackupRecord getBackupRecord()
public void setSheetName(int sheetnum, java.lang.String sheetname)
sheetnum
- the sheet number (0 based)sheetname
- the name for the sheetpublic boolean doesContainsSheetName(java.lang.String name, int excludeSheetIdx)
name
- the name to test (case insensitive match)excludeSheetIdx
- the sheet to exclude from the check or -1 to include all sheets in the check.public void setSheetOrder(java.lang.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 java.lang.String getSheetName(int sheetIndex)
sheetIndex
- the sheet number (0 based)public boolean isSheetHidden(int sheetnum)
isSheetVeryHidden(int)
)sheetnum
- the sheet number (0 based)public boolean isSheetVeryHidden(int sheetnum)
isSheetHidden(int)
)sheetnum
- the sheet number (0 based)public SheetVisibility getSheetVisibility(int sheetnum)
isSheetVeryHidden(int)
)sheetnum
- the sheet number (0 based)public void setSheetHidden(int sheetnum, boolean hidden)
sheetnum
- The sheet numberhidden
- True to mark the sheet as hidden, false otherwisepublic void setSheetHidden(int sheetnum, SheetVisibility visibility)
sheetnum
- The sheet numbervisibility
- the sheet visibility to set (visible, hidden, very hidden)public int getSheetIndex(java.lang.String name)
name
- sheet namepublic void removeSheet(int sheetIndex)
sheetIndex
- zero based sheet indexpublic int getNumSheets()
public int getNumExFormats()
public ExtendedFormatRecord getExFormatAt(int index)
index
- of the Extended format record (0-based)public void removeExFormatRecord(ExtendedFormatRecord rec)
rec
- the ExtendedFormatRecordpublic void removeExFormatRecord(int index)
index
- of the Extended format record (0-based)public ExtendedFormatRecord createCellXF()
public StyleRecord getStyleRecord(int xfIndex)
xfIndex
- the extended format indexnull
if it that ExtendedFormat doesn't have a Style set.public void updateStyleRecord(int oldXf, int newXf)
oldXf
- the extended format index that was previously associated with this StyleRecordnewXf
- the extended format index that is now associated with this StyleRecordpublic StyleRecord createStyleRecord(int xfIndex)
xfIndex
- the extended format indexpublic int addSSTString(UnicodeString string)
string
- the string to be added to the SSTRecordpublic UnicodeString getSSTString(int str)
str
- the index into the SST tablepublic void insertSST()
createExtendedSST()
,
SSTRecord
public int serialize(int offset, byte[] data)
offset
- of the data to be writtendata
- array of bytes to write this topublic void preSerialize()
public int getSize()
public int linkExternalWorkbook(java.lang.String name, Workbook externalWorkbook)
public java.lang.String findSheetFirstNameFromExternSheet(int externSheetIndex)
externSheetIndex
- extern sheet indexpublic java.lang.String findSheetLastNameFromExternSheet(int externSheetIndex)
public EvaluationWorkbook.ExternalSheet getExternalSheet(int externSheetIndex)
public EvaluationWorkbook.ExternalName getExternalName(int externSheetIndex, int externNameIndex)
public int getFirstSheetIndexFromExternSheetIndex(int externSheetNumber)
externSheetNumber
- The external sheet number to convertpublic int getLastSheetIndexFromExternSheetIndex(int externSheetNumber)
externSheetNumber
- The external sheet number to convertpublic short checkExternSheet(int sheetNumber)
sheetNumber
- local sheet numberpublic short checkExternSheet(int firstSheetNumber, int lastSheetNumber)
firstSheetNumber
- first local sheet numberlastSheetNumber
- last local sheet numberpublic int getExternalSheetIndex(java.lang.String workbookName, java.lang.String sheetName)
public int getExternalSheetIndex(java.lang.String workbookName, java.lang.String firstSheetName, java.lang.String lastSheetName)
public int getNumNames()
public NameRecord getNameRecord(int index)
index
- name indexpublic NameCommentRecord getNameCommentRecord(NameRecord nameRecord)
nameRecord
- name record who's comment is required.null
if there isn't one for the given name.public NameRecord createName()
public NameRecord addName(NameRecord name)
name
- the name record to be addedpublic NameRecord createBuiltInName(byte builtInName, int sheetNumber)
builtInName
- the built-in namesheetNumber
- the sheet numberpublic void removeName(int nameIndex)
nameIndex
- name indexpublic void updateNameCommentRecordCache(NameCommentRecord commentRecord)
NameCommentRecord
is added or the name it references
is renamed, then this will update the lookup cache for it.commentRecord
- the comment recordpublic short getFormat(java.lang.String format, boolean createIfNotFound)
format
- the format stringcreateIfNotFound
- creates a new format if format not foundpublic java.util.List<FormatRecord> getFormats()
public int createFormat(java.lang.String formatString)
formatString
- the format stringFormatRecord
,
Record
public Record findFirstRecordBySid(short sid)
sid
- the sidnull
if it wasn't foundpublic int findFirstRecordLocBySid(short sid)
sid
- The sid of the record to matchpublic Record findNextRecordBySid(short sid, int pos)
sid
- the sidpos
- specifies the n-th matching sidnull
if it wasn't foundpublic java.util.List<HyperlinkRecord> getHyperlinks()
public java.util.List<Record> getRecords()
public boolean isUsing1904DateWindowing()
public PaletteRecord getCustomPalette()
public DrawingManager2 findDrawingGroup()
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 boolean isWriteProtected()
true
if the workbook is write protectedpublic void writeProtectWorkbook(java.lang.String password, java.lang.String username)
password
- the passwordusername
- the usernamepublic void unwriteProtectWorkbook()
public java.lang.String resolveNameXText(int refIndex, int definedNameIndex)
refIndex
- Index to REF entry in EXTERNSHEET record in the Link TabledefinedNameIndex
- zero-based to DEFINEDNAME or EXTERNALNAME recordpublic NameXPtg getNameXPtg(java.lang.String name, int sheetRefIndex, UDFFinder udf)
name
- the name of an external function, typically a name of a UDFsheetRefIndex
- the sheet ref index, or -1 if not knownudf
- locator of user-defiend functions to resolve names of VBA and Add-In functionspublic void cloneDrawings(InternalSheet sheet)
sheet
- the cloned sheetpublic NameRecord cloneFilter(int filterDbNameIndex, int newSheetIndex)
public void updateNamesAfterCellShift(FormulaShifter shifter)
shifter
- the formula shifterpublic RecalcIdRecord getRecalcId()
HSSFWorkbook.setForceFormulaRecalculation(boolean)
public boolean changeExternalReference(java.lang.String oldUrl, java.lang.String newUrl)
oldUrl
- The old URL to search for and which is to be replacednewUrl
- The URL replacement@Internal public WorkbookRecordList getWorkbookRecordList()
Copyright 2020 The Apache Software Foundation or its licensors, as applicable.