Top Description Fields Constructors Methods
org.apache.poi.hssf.model

public final Class InternalWorkbook

extends Object
Class Inheritance
Annotations
@Internal
Static Imports
org.apache.logging.log4j.util.Unbox.box

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 https://sc.openoffice.org/excelfileformat.pdf before even attempting to use this.

See Also
HSSFWorkbook

Field Summary

Modifier and TypeField and Description
public static final String
BOOK

Crystal exports may use this for a regular .xls file.

private final List<BoundSheetRecord>
boundsheets

holds the "boundsheet" records (aka bundlesheet) so that they can have their reference to their "BOF" marker

private static final short
CODEPAGE

constant used to set the "codepage" wherever "codepage" is set in records (which is duplicated in more than one record)

private final Map<String, NameCommentRecord>
commentRecords

Hold the NameCommentRecords indexed by the name of the NameRecord to which they apply.

private DrawingManager2
private final List<EscherBSERecord>
private FileSharingRecord
private final List<FormatRecord>
private final List<HyperlinkRecord>
private LinkTable
private static final Logger
private static final int
MAX_SENSITIVE_SHEET_NAME_LEN

Excel silently truncates long sheet names to 31 chars.

private int
maxformatid

holds the max format id

private int
numfonts

the number of font records

private int
numxfs

the number of extended format records

public static final String
OLD_WORKBOOK_DIR_ENTRY_NAME

Name of older (pre-Excel 97) Workbook streams, which aren't supported by HSSFWorkbook, only by OldExcelExtractor

private final 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.

private boolean
uses1904datewindowing

whether 1904 date windowing is being used

private WindowOneRecord
public static final String
public static final List<String>
WORKBOOK_DIR_ENTRY_NAMES

Normally, the Workbook will be in a POIFS Stream called "Workbook".

public static final List<String>
private WriteAccessRecord
private WriteProtectRecord

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
public NameRecord

Returns:

the given name record
addName
(NameRecord
the name record to be added
name
)

adds a name record

public int

Returns:

index of the string within the SSTRecord
addSSTString
(UnicodeString
the string to be added to the SSTRecord
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 boolean

Returns:

true if the oldUrl was found and replaced with newUrl. Otherwise false
changeExternalReference
(String
The old URL to search for and which is to be replaced
oldUrl
,
String
The URL replacement
newUrl
)

Changes an external referenced file to another file.

public short

Returns:

index to extern sheet
checkExternSheet
(int
local sheet number
sheetNumber
)

Returns the extern sheet number for specific sheet number.

public short

Returns:

index to extern sheet
checkExternSheet
(int
first local sheet number
firstSheetNumber
,
int
last local sheet number
lastSheetNumber
)

Returns the extern sheet number for specific range of sheets.

private void
checkSheets(int sheetnum)

if we're trying to address one more sheet than we have, go ahead and add it!

public void
cloneDrawings(InternalSheet
the cloned sheet
sheet
)

Check if the cloned sheet has drawings.

public NameRecord
cloneFilter(int filterDbNameIndex, int newSheetIndex)

private static BackupRecord
createBackup()

creates the Backup record with backup set to 0.

private static BOFRecord
private static BookBoolRecord
createBookBool()

creates the BookBool record with saveLinkValues set to 0.

private static BoundSheetRecord

Returns:

record containing a BoundSheetRecord
createBoundSheet
(int
either sheet 0,1 or 2.
id
)

create a "bound sheet" or "bundlesheet" (depending who you ask) record Always sets the sheet's bof to 0.

public NameRecord

Returns:

a new NameRecord
createBuiltInName
(byte
the built-in name
builtInName
,
int
the sheet number
sheetNumber
)

Generates a NameRecord to represent a built-in region

public ExtendedFormatRecord

Returns:

ExtendedFormatRecord that was created
createCellXF
()

creates a new Cell-type Extended Format Record and adds it to the end of ExtendedFormatRecords collection

private static CodepageRecord
private static CountryRecord
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

private static DateWindow1904Record
createDateWindow1904()

creates the DateWindow1904 record with windowing set to 0.

public void
createDrawingGroup()

Creates a primary drawing group record.

private static DSFRecord
private static ExtendedFormatRecord
createExtendedFormat(int
the number of the extended format record to create (meaning its position in a file as MS Excel would create it.)
id
)

Creates an ExtendedFormatRecord object

private static ExtendedFormatRecord
createExtendedFormat(int fontIndex, int formatIndex, int cellOptions, int indentionOptions)

private static ExtendedFormatRecord

Returns:

ExtendedFormatRecord with initial defaults (cell-type)
createExtendedFormat
()

creates an default cell type ExtendedFormatRecord object.

private static ExtSSTRecord
createExtendedSST()

Creates the ExtendedSST record with numstrings per bucket set to 0x8.

private static FnGroupCountRecord
createFnGroupCount()

creates the FnGroupCount record containing the Magic number constant of 14.

private static FontRecord
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

private static FormatRecord
createFormat(int
the number of the format record to create (meaning its position in a file as M$ Excel would create it.)
id
)

Creates a FormatRecord object

public int

Returns:

the index code of the format record.
createFormat
(String
the format string
formatString
)

Creates a FormatRecord, inserts it, and returns the index code.

private static HideObjRecord
createHideObj()

creates the HideObj record with hide object set to 0.

private static MMSRecord
public NameRecord

Returns:

new name record
createName
()

creates new name

public FontRecord

Returns:

FontRecord that was just created
createNewFont
()

creates a new font record and adds it to the "font table".

private static PaletteRecord
createPalette()

Creates a palette record initialized to the default palette

private static PasswordRecord

Returns:

a new Password record with password set to 0x0000 (no password).
createPassword
()

private static PasswordRev4Record

Returns:

a new PasswordRev4 record with password set to 0.
createPasswordRev4
()

private static PrecisionRecord
createPrecision()

creates the Precision record with precision set to true.

private static ProtectRecord

Returns:

a new Protect record with protect set to false.
createProtect
()

private static ProtectionRev4Record

Returns:

a new ProtectionRev4 record with protect set to false.
createProtectionRev4
()

private static RefreshAllRecord

Returns:

a new RefreshAll record with refreshAll set to false. (do not refresh all calcs)
createRefreshAll
()

private static StyleRecord
createStyle(int
the number of the style record to create (meaning its position in a file as MS Excel would create it.
id
)

Creates a StyleRecord object

public StyleRecord

Returns:

a new StyleRecord
createStyleRecord
(int
the extended format index
xfIndex
)

Creates a new StyleRecord, for the given Extended Format index, and adds it onto the end of the records collection

private static TabIdRecord
createTabId()

creates the TabId record containing an array

private static UseSelFSRecord

Returns:

a new UseSelFS object with the use natural language flag set to 0 (false)
createUseSelFS
()

private static WindowOneRecord
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

private static WindowProtectRecord

Returns:

a new WindowProtect record with protect set to false.
createWindowProtect
()

public static InternalWorkbook

Returns:

Workbook object
createWorkbook
(List<Record>
an array of Record objects
recs
)

read support for low level API.

public static InternalWorkbook

Returns:

an empty workbook object
createWorkbook
()

Creates an empty workbook object with three blank sheets and all the empty fields.

private static WriteAccessRecord
createWriteAccess()

creates the WriteAccess record containing the logged in user's name

public boolean

Returns:

true if the sheet contains the name, false otherwise.
doesContainsSheetName
(String
the name to test (case insensitive match)
name
,
int
the sheet to exclude from the check or -1 to include all sheets in the check.
excludeSheetIdx
)

Determines whether a workbook contains the provided sheet name.

public DrawingManager2

Returns:

the primary drawing group
findDrawingGroup
()

Finds the primary drawing group, if one already exists

private static DrawingManager2
public Record

Returns:

the matching record or null if it wasn't found
findFirstRecordBySid
(short
the sid
sid
)

Returns the first occurance of a record matching a particular sid.

public int

Returns:

The index of -1 if no match made.
findFirstRecordLocBySid
(short
The sid of the record to match
sid
)

Returns the index of a record matching a particular sid.

public Record

Returns:

the matching record or null if it wasn't found
findNextRecordBySid
(short
the sid
sid
,
int
specifies the n-th matching sid
pos
)

Returns the next occurance of a record matching a particular sid.

public String

Returns:

first sheet name.
findSheetFirstNameFromExternSheet
(int
extern sheet index
externSheetIndex
)

Finds the first sheet name by his extern sheet index

public String
findSheetLastNameFromExternSheet(int externSheetIndex)

private String
findSheetNameFromIndex(int internalSheetIndex)

private void
fixTabIdRecord()

make the tabid record look like the current situation.

public BackupRecord

Returns:

the position of the backup record
getBackupRecord
()

Returns the position of the backup record.

private BoundSheetRecord
getBoundSheetRec(int sheetIndex)

public EscherBSERecord
getBSERecord(int pictureIndex)

public PaletteRecord

Returns:

the custom palette
getCustomPalette
()

Returns the custom palette in use for this workbook; if a custom palette record does not exist, then it is created.

public DrawingManager2
public ExtendedFormatRecord

Returns:

ExtendedFormatRecord at the given index
getExFormatAt
(int
of the Extended format record (0-based)
index
)

gets the ExtendedFormatRecord at the given 0-based index

public EvaluationWorkbook.ExternalName
getExternalName(int externSheetIndex, int externNameIndex)

public EvaluationWorkbook.ExternalSheet
getExternalSheet(int externSheetIndex)

public int
getExternalSheetIndex(String workbookName, String sheetName)

public int
getExternalSheetIndex(String workbookName, String firstSheetName, String lastSheetName)

public FileSharingRecord
public int

Returns:

The index to the sheet found.
getFirstSheetIndexFromExternSheetIndex
(int
The external sheet number to convert
externSheetNumber
)

Finds the (first) sheet index for a particular external sheet number.

public int

Returns:

the font index
getFontIndex
(FontRecord
the font
font
)

Retrieves the index of the given font

public FontRecord

Returns:

FontRecord located at the given index
getFontRecordAt
(int
the index to look at (0 or greater but NOT 4)
idx
)

gets the font record at the given index in the font table.

public short

Returns:

the format id of a format that matches or -1 if none found and createIfNotFound
getFormat
(String
the format string
format
,
boolean
creates a new format if format not found
createIfNotFound
)

Returns a format index that matches the passed in format.

public List<FormatRecord>

Returns:

ArrayList of FormatRecords in the notebook
getFormats
()

Returns the list of FormatRecords in the workbook.

public int

Returns:

The index to the sheet found.
getLastSheetIndexFromExternSheetIndex
(int
The external sheet number to convert
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)

public NameCommentRecord

Returns:

name comment record or null if there isn't one for the given name.
getNameCommentRecord
(final NameRecord
name record who's comment is required.
nameRecord
)

gets the name comment record

public NameRecord

Returns:

name record
getNameRecord
(int
name index
index
)

gets the name record

public NameXPtg

Returns:

the external name or null
getNameXPtg
(String
the name of an external function, typically a name of a UDF
name
,
int
the sheet ref index, or -1 if not known
sheetRefIndex
,
UDFFinder
locator of user-defined functions to resolve names of VBA and Add-In functions
udf
)

public NameXPtg
public int

Returns:

number of font records in the "font table"
getNumberOfFontRecords
()

gets the number of font records

public int

Returns:

int count of ExtendedFormat records
getNumExFormats
()

get the number of ExtendedFormat records contained in this workbook.

public int

Returns:

number of names
getNumNames
()

gets the total number of names

public int
public int

Returns:

number of BoundSheet records
getNumSheets
()

returns the number of boundsheet objects contained in this workbook.

private LinkTable
getOrCreateLinkTable()

lazy initialization Note - creating the link table causes creation of 1 EXTERNALBOOK and 1 EXTERNALSHEET record

public RecalcIdRecord

Returns:

a new RecalcIdRecord
getRecalcId
()

Get or create RecalcIdRecord

public List<Record>
public int

Returns:

sheet index or -1 if it was not found.
getSheetIndex
(String
sheet name
name
)

get the sheet's index

public String

Returns:

sheetname the name for the sheet
getSheetName
(int
the sheet number (0 based)
sheetIndex
)

gets the name for a given sheet.

public SheetVisibility

Returns:

True if sheet is hidden
getSheetVisibility
(int
the sheet number (0 based)
sheetnum
)

Gets the hidden flag for a given sheet.

public int
public NameRecord

Returns:

null if no builtin NameRecord matches
getSpecificBuiltinRecord
(byte
byte representation of the builtin name to match
name
,
int
1-based sheet number
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

public UnicodeString

Returns:

String containing the SST String
getSSTString
(int
the index into the SST table
str
)

given an index into the SST table, this function returns the corresponding String value

public StyleRecord

Returns:

the StyleRecord, null if it that ExtendedFormat doesn't have a Style set.
getStyleRecord
(int
the extended format index
xfIndex
)

Returns the StyleRecord for the given xfIndex, or null if that ExtendedFormat doesn't have a Style set.

public WindowOneRecord
public WorkbookRecordList

Returns:

The list of records.
getWorkbookRecordList
()

Only for internal calls - code based on this is not supported ...

public WriteAccessRecord
public WriteProtectRecord
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

Returns:

True if sheet is hidden
isSheetHidden
(int
the sheet number (0 based)
sheetnum
)

Gets the hidden flag for a given sheet.

public boolean

Returns:

True if sheet is very hidden
isSheetVeryHidden
(int
the sheet number (0 based)
sheetnum
)

Gets the very hidden flag for a given sheet.

public boolean

Returns:

true if using 1904 date windowing
isUsing1904DateWindowing
()

Whether date windowing is based on 1/2/1904 or 1/1/1900.

public boolean

Returns:

true if the workbook is write protected
isWriteProtected
()

is the workbook protected with a password (not encrypted)?

public int
linkExternalWorkbook(String name, Workbook externalWorkbook)

public void
preSerialize()

Perform any work necessary before the workbook is about to be serialized.

public void
removeBuiltinRecord(byte
byte representation of the builtin to match
name
,
int
zero-based sheet reference
sheetIndex
)

Removes the specified Builtin NameRecord that matches the name and index

public void
removeExFormatRecord(ExtendedFormatRecord
the ExtendedFormatRecord
rec
)

Removes the given ExtendedFormatRecord record from the file's list.

public void
removeExFormatRecord(int
of the Extended format record (0-based)
index
)

Removes ExtendedFormatRecord record with given index from the file's list.

public void
removeFontRecord(FontRecord
the font record
rec
)

Removes the given font record from the file's list.

public void
removeName(int
name index
nameIndex
)

removes the name

public void
removeSheet(int
zero based sheet index
sheetIndex
)

public String

Returns:

the string representation of the defined or external name
resolveNameXText
(int
Index to REF entry in EXTERNSHEET record in the Link Table
refIndex
,
int
zero-based to DEFINEDNAME or EXTERNALNAME record
definedNameIndex
)

public int

Returns:

the length of serialized bytes
serialize
(int
of the data to be written
offset
,
byte[]
array of bytes to write this to
data
)

Serializes all records int the worksheet section into a big byte array.

public void
setSheetBof(int
the number of the sheet to set the positing of the bof for
sheetIndex
,
int
the actual bof position
pos
)

Sets the BOF for a given sheet

public void
setSheetHidden(int
The sheet number
sheetnum
,
boolean
True to mark the sheet as hidden, false otherwise
hidden
)

Hide or unhide a sheet

public void
setSheetHidden(int
The sheet number
sheetnum
,
SheetVisibility
the sheet visibility to set (visible, hidden, very hidden)
visibility
)

Hide or unhide a sheet.

public void
setSheetName(int
the sheet number (0 based)
sheetnum
,
final String
the name for the sheet
sheetname
)

sets the name for a given sheet.

public void
setSheetOrder(String
the name of the sheet to reorder
sheetname
,
int
the position that we want to insert the sheet into (0 based)
pos
)

sets the order of appearance for a given sheet.

public void
unwriteProtectWorkbook()

removes the write protect flag

public void
updateNameCommentRecordCache(final NameCommentRecord
the comment record
commentRecord
)

If a NameCommentRecord is added or the name it references is renamed, then this will update the lookup cache for it.

public void
updateNamesAfterCellShift(FormulaShifter
the formula shifter
shifter
)

Updates named ranges due to moving of cells

public void
updateStyleRecord(int
the extended format index that was previously associated with this StyleRecord
oldXf
,
int
the extended format index that is now associated with this StyleRecord
newXf
)

Update the StyleRecord to point to the new given index.

public void
writeProtectWorkbook(String
the password
password
,
String
the username
username
)

protect a workbook with a password (not encrypted, just sets writeprotect flags and the password.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait