Microsoft has not published a specification of BIFF2, BIFF3 or BIFF4 on its own:
[MS-XLS] covers only BIFF8. The facts on this page come from Excel File Format,
the description of BIFF2 to BIFF8 written for OpenOffice.org by Daniel Rentz (sections 2.2,
2.3, 2.5.2, 2.5.13 and 5), and were checked against the real files
testEXCEL_3.xls and testEXCEL_4.xls from the Apache POI test
data. All numbers are little-endian.
Versions and file
| Excel | BIFF | Document | BOF record |
|---|---|---|---|
| 2.x | BIFF2 | Worksheet | 0x0009 |
| 3.0 | BIFF3 | Worksheet | 0x0209 |
| 4.0 | BIFF4 | Worksheet | 0x0409 |
The document is a plain stream file: the whole file is the record stream, from a BOF
record to an EOF record (0x000A), and it holds one sheet.
Workbooks of several sheets inside a compound file start with BIFF5.
Records
| Offset | Size | Field | Meaning |
|---|---|---|---|
0 | 2 | record number | The record type. |
2 | 2 | length | Length of the data. |
4 | length | data | The record’s fields. |
Record numbers that differ between versions follow a pattern: BIFF3 and BIFF4 add
0x0200 to the BIFF2 number (NUMBER is 0x0003,
0x0203), and BIFF4 uses 0x0400 for FORMULA and FORMAT.
BOF
| Version | Offset | Size | Field | Meaning |
|---|---|---|---|---|
| BIFF2 | 0 | 2 | version | Not used. |
| BIFF2 | 2 | 2 | type | 0x0010 sheet, 0x0020 chart, 0x0040 macro sheet. |
| BIFF3, BIFF4 | 0 | 2 | version | Not used. |
| BIFF3, BIFF4 | 2 | 2 | type | As BIFF2, and 0x0100 for a workspace file. |
| BIFF3, BIFF4 | 4 | 2 | – | Not used. |
Some programs write a BOF with the BIFF5 number 0x0809 and put the
version in the first field instead: 0x0200 BIFF2, 0x0300
BIFF3, 0x0400 BIFF4 (0x0500 BIFF5, 0x0600
BIFF8). A reader that wants to accept such files uses the version field then and
ignores the record number.
Text
All versions up to BIFF5 store byte strings: the length, followed by that many 8-bit
characters, not zero-terminated. The length is 8 bits or 16 bits depending on the
record, and the character set comes from the CODEPAGE record (0x0042) or
the font. In BIFF2 a LABEL record has an 8-bit length, so a string is at most 255
characters; in BIFF3 and BIFF4 it is 16 bits.
Cell attributes (BIFF2)
Every BIFF2 cell record holds a 3-byte attribute field after its row and column, and BIFF3 and BIFF4 hold a 2-byte XF index there instead.
| Byte | Bits | Meaning |
|---|---|---|
0 | 5–0 (0x3F) | Index to an XF record. The value 63 means an IXFE record (0x0044, one 2-byte XF index) came before this cell record and holds the real index. |
0 | 6 (0x40) | 1 = the cell is locked. |
0 | 7 (0x80) | 1 = the formula is hidden. |
1 | 5–0 (0x3F) | Index to a FORMAT record. |
1 | 7–6 (0xC0) | Index to a FONT record. |
2 | 2–0 (0x07) | Horizontal alignment. |
2 | 3, 4, 5, 6 | 1 = a black border on the left, right, top, bottom of the cell. |
2 | 7 (0x80) | 1 = the cell has a shaded background. |
Cell records
Each cell record starts with the row (2 bytes) and the column (2 bytes), then the attributes (3 bytes in BIFF2) or the XF index (2 bytes in BIFF3 and BIFF4), then the value. The table gives the first offset of the value.
| Cell | BIFF2 | BIFF3 | BIFF4 | Value, BIFF2 (from offset 7) | Value, BIFF3 and BIFF4 (from offset 6) |
|---|---|---|---|---|---|
| BLANK | 0x0001 | 0x0201 | 0x0201 | none | none |
| INTEGER | 0x0002 | – | – | unsigned 16-bit integer | replaced by RK |
| NUMBER | 0x0003 | 0x0203 | 0x0203 | IEEE 754 double (8 bytes) | IEEE 754 double (8 bytes) |
| LABEL | 0x0004 | 0x0204 | 0x0204 | byte string, 8-bit length | byte string, 16-bit length |
| BOOLERR | 0x0005 | 0x0205 | 0x0205 | value (1 byte), then 0 = Boolean or 1 = error code | the same, from offset 6 |
| FORMULA | 0x0006 | 0x0206 | 0x0406 | result (8 bytes), 1 byte 0 = do not recalculate, 1 = always, then the tokens at offset 16 | result (8 bytes), option flags (2 bytes: 0x0001 recalculate always, 0x0002 calculate on open), then the tokens at offset 16 |
| STRING | 0x0007 | 0x0207 | 0x0207 | the text result of the FORMULA record before it | |
| RK | – | 0x027E | 0x027E | – | a number packed in 4 bytes |
MULRK (0x00BD) and MULBLANK (0x00BE) first appear in BIFF5.
Other sheet records
| Record | BIFF2 | BIFF3 | BIFF4 | Layout |
|---|---|---|---|---|
| DIMENSION | 0x0000 | 0x0200 | 0x0200 | First used row, last used row plus 1, first used column, last used column plus 1 (2 bytes each); BIFF3 and BIFF4 add 2 unused bytes. |
| ROW | 0x0008 | 0x0208 | 0x0208 | BIFF2: row index, first and last-plus-1 column with a cell record, a height word (bits 14–0 the height in twips; bit 15 set = default height), 2 unused bytes, a flag byte telling whether a default attribute field follows, a position offset, 3 bytes of default attributes and a 2-byte XF index. |
| COLWIDTH | 0x0024 | – | – | First column (1 byte), last column (1 byte), width in 1/256 of the width of the zero character in the default font. |
| COLINFO | – | 0x007D | 0x007D | replaces COLWIDTH; layout in Columns and default sizes |
| XF | 0x0043 | 0x0243 | 0x0443 | extended format; BIFF5 and BIFF8 use 0x00E0 |
| FONT | 0x0031 | 0x0231 | 0x0231 | BIFF5 and BIFF8 use 0x0031 |
| FORMAT | 0x001E | 0x001E | 0x041E | number format; layouts in FONT, FORMAT, XF |
| DEFAULTROWHEIGHT | 0x0025 | 0x0225 | 0x0225 | see Columns and default sizes |
| WINDOW2 | 0x003E | 0x023E | 0x023E | see WINDOW2 |
| DEFINEDNAME | 0x0018 | 0x0218 | 0x0218 | see Names |
| EXTERNALNAME | 0x0023 | 0x0223 | 0x0223 | see Names |
| STYLE, PALETTE | – | 0x0293, 0x0092 | 0x0293, 0x0092 | see FONT, FORMAT, XF |
| NOTE | 0x001C in all three | |||
FONT, FORMAT, XF, STYLE and PALETTE
All layouts follow the specification's sections 5.45 (FONT), 5.49 (FORMAT), 5.115 (XF), 5.103 (STYLE) and 5.74 (PALETTE).
- FONT: height in twips (2 bytes) and a flag word (
0x01bold,0x02italic,0x04underline,0x08strike-out,0x10outline,0x20shadow,0x40condensed,0x80extended). BIFF2 then has the name (8-bit length); an optional FONTCOLOR record follows. BIFF3 and BIFF4 have a colour index after the flags and the name from offset 6. The font with index 4 is never written, so later indexes are one higher than the position in the list. - FORMAT: the format string as a byte string. BIFF4 has 2 unused bytes before it. A format is referenced by its zero-based position in the list of FORMAT records, not by a stored index. The built-in formats are written in full: BUILTINFMTCOUNT (
0x001Fin BIFF2) says how many, and user formats follow. In the real BIFF2 fileoo-formula_import_biff2.xlsthe value0x15means 21 built-in formats, so index 21 is the first user format. - XF, BIFF2 (4 bytes): FONT index; unused byte; a byte with the FORMAT index in bits 5–0, locked in bit 6 and hidden in bit 7; a byte with the horizontal alignment in bits 2–0, black borders left, right, top, bottom in bits 3–6 and shading in bit 7. A BIFF2 cell uses these same flags in its own attribute bytes (above).
- XF, BIFF3 (12 bytes): FONT index, FORMAT index, a byte with locked, hidden and cell or style XF, a byte of used-attribute flags, a word with horizontal alignment (bits 2–0), wrap (bit 3) and the parent style XF (bits 15–4), a 2-byte background (pattern bits 5–0, pattern colour bits 10–6, background colour bits 15–11) and 4 bytes of borders (top, left, bottom, right: a 3-bit line style then a 5-bit colour index each).
- XF, BIFF4 (12 bytes): as BIFF3, but the protection and parent style share a word and the alignment byte at offset 4 adds vertical alignment (bits 5–4: top, centred, bottom) and orientation (bits 7–6: none, stacked, 90 degrees counterclockwise, 90 degrees clockwise). Horizontal alignment 5 (justified) and 6 (centred across selection) exist from BIFF4 on.
- STYLE (
0x0293, BIFF3 and later): a word with the XF index in bits 11–0 and the built-in flag in bit 15, then a built-in style id and level, or the style name. - PALETTE (
0x0092): a colour count (16 in BIFF3 and BIFF4) and then that many 4-byte RGB entries (red, green, blue, unused).
Columns and default sizes
- COLWIDTH (
0x0024, BIFF2): first column (1 byte), last column (1 byte), width (2 bytes) in 1/256 of a zero character (section 5.20). - COLUMNDEFAULT (
0x0020, BIFF2): 2 unused bytes, first column, last column, then one 3-byte attribute field (above) for each column in the range (section 5.19). - COLINFO (
0x007D, BIFF3 and later): first column, last column, width in 1/256 of a zero character, XF index (2 bytes each), a flag word (0x0001hidden, bits 10–8 outline level,0x1000collapsed) and 2 unused bytes (section 5.18). - DEFCOLWIDTH (
0x0055): default width in characters, in all versions (section 5.32). - DEFAULTROWHEIGHT: BIFF2 is one word (bits 14–0 the height in twips, bit 15 = not manually changed). BIFF3 and BIFF4 have a flag word (
0x01height differs from the default font,0x02hidden,0x04extra space above,0x08extra space below) and then the height (section 5.31).
WINDOW2
Section 5.110. BIFF2 (0x003E): a flag byte (formulas shown, grid shown, row and column headers shown, panes frozen, zero values shown), the first visible row at offset 1, the first visible column at offset 3, a byte at offset 5 that says the grid colour is automatic, and the grid colour as RGB. BIFF3 and BIFF4 (0x023E): an option word, the first visible row, the first visible column and the grid colour.
Names (DEFINEDNAME and EXTERNALNAME)
DEFINEDNAME is section 5.33. BIFF2 (0x0018): option flags (0x02 function macro, 0x04 complex), a function-or-command byte, a keyboard shortcut byte, the name length at offset 3, the length of the formula at offset 4, the name at offset 5, the formula tokens and a repeat of the formula length. BIFF3 and BIFF4 (0x0218): an option word, a keyboard byte, the name length at offset 3, a 2-byte formula length at offset 4, the name at offset 6 and the formula tokens. The option word has hidden 0x0001, function 0x0002, Visual Basic 0x0004, macro 0x0008, complex 0x0010, built-in 0x0020, and from BIFF4 a function group in 0x0FC0.
A built-in name is stored as its one-byte code: 0 Consolidate_Area, 1 Auto_Open, 2 Auto_Close, 3 Extract, 4 Database, 5 Criteria, 6 Print_Area, 7 Print_Titles, 8 Recorder, 9 Data_Form. BIFF2 files written by Excel spell built-in names out in full, and a name may have no formula at all (a zero length), as in oo-cells_import_biff2.xls.
EXTERNALNAME (section 5.39): a byte string with an 8-bit length, then formula data. BIFF3 and BIFF4 start with an option word (0x01 built-in, 0x02 automatic link, 0x04 picture link); DDE links end with the last result as a constant array.
Formula tokens
The token list of section 3.4.7 is shared with later versions; these sizes differ. The size is the token including its id byte, for BIFF2, BIFF3 and BIFF4.
| Token | BIFF2 | BIFF3 | BIFF4 |
|---|---|---|---|
| tExp, tTbl | 4 | 5 | 5 |
| tFunc | 3 | 3 | 4 |
| tFuncVar | 4 | 4 | 5 |
| tName | 8 | 11 | 11 |
| tMemArea | 5 | 7 | 7 |
| tMemFunc | 2 | 3 | 3 |
| tSheet | 8 | 11 | 11 |
| tEndSheet | 4 | 5 | 5 |
tRef is 4 bytes and tArea 7 bytes in all three; tErr and tBool are 2, tInt 3 and tNum 9. tSheet and tEndSheet exist only in BIFF2 to BIFF4. The token 0x38 (tFuncCE) exists in BIFF2 and BIFF3 only. The data of tAttr (section 3.10.5) is 1 byte wide in BIFF2 (volatile, if, skip, sum, assign) and 2 bytes wide from BIFF3; in BIFF2 tAttrChoose has a 1-byte count and 1-byte jump entries. tAttrSpace exists only from BIFF3.
Record order
Section 4.2.1, a BIFF2 worksheet: BOF, FILEPASS, INDEX, CODEPAGE, the calculation records, PRINTHEADERS, PRINTGRIDLINES, DEFAULTROWHEIGHT, page breaks, FONT, FONT2, FONTCOLOR, page setup records, BACKUP, the external link table, BUILTINFMTCOUNT, FORMAT, DEFINEDNAME, protection records, XF, DEFCOLWIDTH, COLWIDTH, DIMENSION, COLUMNDEFAULT, the row blocks, NOTE, WINDOW1, the view settings and EOF.
Section 4.2.2, BIFF3: the same, with GRIDSET, HCENTER, VCENTER, GUTS, COUNTRY, HIDEOBJ and SHEETPR added, XF and STYLE in place of the BIFF2 XF list, an optional PALETTE, and DEFCOLWIDTH with COLINFO. Section 4.2.3, the order for BIFF4, is marked “2do” in the source and is not given.
Workspace files (BIFF4W, .xlw)
Section 10.1.1. A BIFF4 workspace starts with a BOF of type 0x0100 and holds SHEETSOFFSET (0x008E, the 4-byte absolute position of the first sheet header) and one SHEETHDR (0x008F) per sheet: a 4-byte length of the sheet's substream and the sheet name as a byte string with an 8-bit length. Each substream is a complete BIFF4 sheet, from a BOF of type 0x0010 to its EOF. INDEX (0x020B) is described in section 10.3, which is marked “2do”. In oo-formula_import_biff4.xlw the workspace has five sheets (Cell, Param, Functions, Array, Table), its SHEETSOFFSET is 0x230, and the stream has six BOF records of 0x0409. The SHEET record (0x0085) in the workspace holds only a name.
Not covered here
The chart records of BIFF2 to BIFF4 are not transcribed on this site; the source describes them in its chapter on charts.
Divergence from the specification
The source marks the record order of a BIFF4 worksheet stream and the workspace INDEX record “2do”, so neither is given here. The record numbers in the tables above were each seen in real files: BIFF2 has the cell, FORMAT 0x001E, FONT 0x0031 and XF 0x0043 numbers (oo-*_biff2.xls); BIFF3 has FORMULA 0x0206, FONT 0x0231, FORMAT 0x001E and XF 0x0243; BIFF4 has 0x0406, 0x0231, 0x041E and 0x0443.
The viewer reads the font, format and style lists of the first sheet of a workspace and uses them for every sheet. Each substream carries its own lists, so a workspace whose sheets differ in those lists may show wrong fonts or formats on the later sheets.
Key programs
LibreOffice Calc imports BIFF2 to BIFF4 sheets and workspaces. The viewer is compared with its CSV output for nine real files (SHA-256 and sources in the project's sample list). Most values match. The differences are:
- Boolean cells: the viewer prints TRUE and FALSE, following the BOOLERR record; LibreOffice's CSV writes 1 and 0.
- Scientific formats such as
0.E+00: the viewer keeps the point (1.E+03), LibreOffice writes 1E+03. - Fraction formats: the number of padding spaces for a zero fraction differs (the viewer follows Excel's behaviour as recorded by Apache POI; LibreOffice pads differently), and the viewer does not show the thousands separator of
#,##0 ?/?. - A number format section with no digit placeholder, such as
"ok";\-General;0;[Red]@: the viewer prints the number and the text (1ok). LibreOffice prints different results for the same format: the text only (ok) for the BIFF3 file and the number only (1) for the BIFF2 and BIFF4 files. No source read for this site says which is right, so the viewer's output is left as it is. - LibreOffice's own check columns in the formula test files print ERR! where LibreOffice itself recalculates a formula differently from the stored result; the viewer shows the stored result.
See also
- BIFF5 stream and records – the next version, a workbook in a compound file
- BIFF8 stream and records – Unicode text and the shared string table