Workbook
extends BIFFwriter
in package
Table of Contents
Properties
- $_data : string|null
- The string containing the data of the BIFF stream.
- $_datasize : int
- The size of the data in bytes. Should be the same as strlen($this->_data).
- $addedFonts : array<string|int, mixed>
- Added fonts. Maps from font's hash => index in workbook.
- $addedNumberFormats : array<string|int, mixed>
- Added number formats. Maps from numberFormat's hash => index in workbook.
- $byteOrder : int|null
- The byte order of this architecture. 0 => little endian, 1 => big endian.
- $codepage : int
- The codepage indicates the text encoding used for strings.
- $colors : array<string|int, mixed>
- Color cache.
- $countryCode : int
- The country code used for localization.
- $escher : Escher|null
- Escher object corresponding to MSODRAWINGGROUP.
- $fontWriters : array<string|int, Font>
- Fonts writers.
- $limit : int
- The maximum length for a BIFF record (excluding record header and length field). See addContinue().
- $numberFormats : array<string|int, mixed>
- Shared number formats.
- $palette : array<string|int, mixed>
- Array containing the colour palette.
- $parser : Parser
- Formula parser.
- $spreadsheet : Spreadsheet
- Workbook.
- $stringTable : array<string|int, mixed>
- Array of unique shared strings in workbook.
- $stringTotal : int
- Total number of shared strings in workbook.
- $stringUnique : int
- Number of unique shared strings in workbook.
- $worksheetOffsets : array<string|int, mixed>
- Offsets of the binary worksheet streams relative to the start of the global workbook stream.
- $worksheetSizes : array<string|int, mixed>
- Sizes of the binary worksheet streams.
- $xfWriters : array<string|int, Xf>
- XF Writers.
Methods
- __construct() : mixed
- Class constructor.
- addColor() : int
- Alter color palette adding a custom color.
- addFont() : int
- Add a font to added fonts.
- addXfWriter() : int
- Add a new XF writer.
- getByteOrder() : int
- Determine the byte order and store it as class data to avoid recalculating it for each call to new().
- getEscher() : Escher|null
- Get Escher object.
- setEscher() : void
- Set Escher object.
- writeData() : string
- General storage function like append, but returns string instead of modifying $this->_data.
- writeEof() : string
- Writes Excel EOF record to indicate the end of a BIFF stream.
- writeWorkbook() : string
- Assemble worksheets into a workbook and send the BIFF data to an OLE storage.
- append() : void
- General storage function.
- storeBof() : void
- Writes Excel BOF record to indicate the beginning of a stream or sub-stream in the BIFF file.
- storeEof() : void
- Writes Excel EOF record to indicate the end of a BIFF stream.
- addContinue() : string
- Excel limits the size of BIFF records. In Excel 5 the limit is 2084 bytes. In Excel 97 the limit is 8228 bytes. Records that are longer than these limits must be split up into CONTINUE blocks.
- calcSheetOffsets() : void
- Calculate offsets for Worksheet BOF records.
- parseDefinedNameValue() : string
- setPaletteXl97() : void
- Sets the colour palette to the Excel 97+ default.
- writeAllDefinedNamesBiff8() : string
- Writes all the DEFINEDNAME records (BIFF8).
- writeAllFonts() : void
- Store the Excel FONT records.
- writeAllNumberFormats() : void
- Store user defined numerical formats i.e. FORMAT records.
- writeAllStyles() : void
- Write all STYLE records.
- writeAllXfs() : void
- Write all XF records.
- writeBoundSheet() : void
- Writes Excel BIFF BOUNDSHEET record.
- writeCodepage() : void
- Stores the CODEPAGE biff record.
- writeCountry() : string
- Stores the COUNTRY record for localization.
- writeDateMode() : void
- Write DATEMODE record to indicate the date system in use (1904 or 1900).
- writeDefinedNameBiff8() : string
- Write a DEFINEDNAME record for BIFF8 using explicit binary formula data.
- writeExternalsheetBiff8() : string
- Writes the Excel BIFF EXTERNSHEET record. These references are used by formulas.
- writeMsoDrawingGroup() : string
- Writes the MSODRAWINGGROUP record if needed. Possibly split using CONTINUE records.
- writeNumberFormat() : void
- Writes Excel FORMAT record for non "built-in" numerical formats.
- writePalette() : void
- Stores the PALETTE biff record.
- writeRecalcId() : string
- Write the RECALCID record.
- writeSharedStringsTable() : string
- Handling of the SST continue blocks is complicated by the need to include an additional continuation byte depending on whether the string is split between blocks or whether it starts at the beginning of the block. (There are also additional complications that will arise later when/if Rich Strings are supported).
- writeShortNameBiff8() : string
- Write a short NAME record.
- writeStyle() : void
- Write Excel BIFF STYLE records.
- writeSupbookInternal() : string
- Write Internal SUPBOOK record.
- writeWindow1() : void
- Write Excel BIFF WINDOW1 record.
Properties
$_data
The string containing the data of the BIFF stream.
public
string|null
$_data
$_datasize
The size of the data in bytes. Should be the same as strlen($this->_data).
public
int
$_datasize
$addedFonts
Added fonts. Maps from font's hash => index in workbook.
private
array<string|int, mixed>
$addedFonts
= []
$addedNumberFormats
Added number formats. Maps from numberFormat's hash => index in workbook.
private
array<string|int, mixed>
$addedNumberFormats
= []
$byteOrder
The byte order of this architecture. 0 => little endian, 1 => big endian.
private
static int|null
$byteOrder
$codepage
The codepage indicates the text encoding used for strings.
private
int
$codepage
$colors
Color cache.
private
array<string|int, mixed>
$colors
$countryCode
The country code used for localization.
private
int
$countryCode
$escher
Escher object corresponding to MSODRAWINGGROUP.
private
Escher|null
$escher
= null
$fontWriters
Fonts writers.
private
array<string|int, Font>
$fontWriters
= []
$limit
The maximum length for a BIFF record (excluding record header and length field). See addContinue().
private
int
$limit
= 8224
Tags
$numberFormats
Shared number formats.
private
array<string|int, mixed>
$numberFormats
= []
$palette
Array containing the colour palette.
private
array<string|int, mixed>
$palette
$parser
Formula parser.
private
Parser
$parser
$spreadsheet
Workbook.
private
Spreadsheet
$spreadsheet
$stringTable
Array of unique shared strings in workbook.
private
array<string|int, mixed>
$stringTable
$stringTotal
Total number of shared strings in workbook.
private
int
$stringTotal
$stringUnique
Number of unique shared strings in workbook.
private
int
$stringUnique
$worksheetOffsets
Offsets of the binary worksheet streams relative to the start of the global workbook stream.
private
array<string|int, mixed>
$worksheetOffsets
= []
$worksheetSizes
Sizes of the binary worksheet streams.
private
array<string|int, mixed>
$worksheetSizes
= []
$xfWriters
XF Writers.
private
array<string|int, Xf>
$xfWriters
= []
Methods
__construct()
Class constructor.
public
__construct(Spreadsheet $spreadsheet, int &$str_total, int &$str_unique, array<string|int, mixed> &$str_table, array<string|int, mixed> &$colors, Parser $parser) : mixed
Parameters
- $spreadsheet : Spreadsheet
-
The Workbook
- $str_total : int
-
Total number of strings
- $str_unique : int
-
Total number of unique strings
- $str_table : array<string|int, mixed>
-
String Table
- $colors : array<string|int, mixed>
-
Colour Table
- $parser : Parser
-
The formula parser created for the Workbook
addColor()
Alter color palette adding a custom color.
public
addColor(string $rgb[, int $default = 0 ]) : int
Parameters
- $rgb : string
-
E.g. 'FF00AA'
- $default : int = 0
Return values
int —Color index
addFont()
Add a font to added fonts.
public
addFont(Font $font) : int
Parameters
- $font : Font
Return values
int —Index to FONT record
addXfWriter()
Add a new XF writer.
public
addXfWriter(Style $style[, bool $isStyleXf = false ]) : int
Parameters
- $style : Style
- $isStyleXf : bool = false
-
Is it a style XF?
Return values
int —Index to XF record
getByteOrder()
Determine the byte order and store it as class data to avoid recalculating it for each call to new().
public
static getByteOrder() : int
Return values
intgetEscher()
Get Escher object.
public
getEscher() : Escher|null
Return values
Escher|nullsetEscher()
Set Escher object.
public
setEscher(Escher|null $escher) : void
Parameters
- $escher : Escher|null
writeData()
General storage function like append, but returns string instead of modifying $this->_data.
public
writeData(string $data) : string
Parameters
- $data : string
-
binary data to write
Return values
stringwriteEof()
Writes Excel EOF record to indicate the end of a BIFF stream.
public
writeEof() : string
Return values
stringwriteWorkbook()
Assemble worksheets into a workbook and send the BIFF data to an OLE storage.
public
writeWorkbook(array<string|int, mixed> $worksheetSizes) : string
Parameters
- $worksheetSizes : array<string|int, mixed>
-
The sizes in bytes of the binary worksheet streams
Return values
string —Binary data for workbook stream
append()
General storage function.
protected
append(string $data) : void
Parameters
- $data : string
-
binary data to append
storeBof()
Writes Excel BOF record to indicate the beginning of a stream or sub-stream in the BIFF file.
protected
storeBof(int $type) : void
Parameters
- $type : int
-
type of BIFF file to write: 0x0005 Workbook, 0x0010 Worksheet
storeEof()
Writes Excel EOF record to indicate the end of a BIFF stream.
protected
storeEof() : void
addContinue()
Excel limits the size of BIFF records. In Excel 5 the limit is 2084 bytes. In Excel 97 the limit is 8228 bytes. Records that are longer than these limits must be split up into CONTINUE blocks.
private
addContinue(string $data) : string
This function takes a long BIFF record and inserts CONTINUE records as necessary.
Parameters
- $data : string
-
The original binary data to be written
Return values
string —A very convenient string of continue blocks
calcSheetOffsets()
Calculate offsets for Worksheet BOF records.
private
calcSheetOffsets() : void
parseDefinedNameValue()
private
parseDefinedNameValue(DefinedName $definedName) : string
Parameters
- $definedName : DefinedName
Return values
stringsetPaletteXl97()
Sets the colour palette to the Excel 97+ default.
private
setPaletteXl97() : void
writeAllDefinedNamesBiff8()
Writes all the DEFINEDNAME records (BIFF8).
private
writeAllDefinedNamesBiff8() : string
So far this is only used for repeating rows/columns (print titles) and print areas.
Return values
stringwriteAllFonts()
Store the Excel FONT records.
private
writeAllFonts() : void
writeAllNumberFormats()
Store user defined numerical formats i.e. FORMAT records.
private
writeAllNumberFormats() : void
writeAllStyles()
Write all STYLE records.
private
writeAllStyles() : void
writeAllXfs()
Write all XF records.
private
writeAllXfs() : void
writeBoundSheet()
Writes Excel BIFF BOUNDSHEET record.
private
writeBoundSheet(Worksheet $sheet, int $offset) : void
Parameters
- $sheet : Worksheet
- $offset : int
-
Location of worksheet BOF
writeCodepage()
Stores the CODEPAGE biff record.
private
writeCodepage() : void
writeCountry()
Stores the COUNTRY record for localization.
private
writeCountry() : string
Return values
stringwriteDateMode()
Write DATEMODE record to indicate the date system in use (1904 or 1900).
private
writeDateMode() : void
writeDefinedNameBiff8()
Write a DEFINEDNAME record for BIFF8 using explicit binary formula data.
private
writeDefinedNameBiff8(string $name, string $formulaData[, int $sheetIndex = 0 ][, bool $isBuiltIn = false ]) : string
Parameters
- $name : string
-
The name in UTF-8
- $formulaData : string
-
The binary formula data
- $sheetIndex : int = 0
-
1-based sheet index the defined name applies to. 0 = global
- $isBuiltIn : bool = false
-
Built-in name?
Return values
string —Complete binary record data
writeExternalsheetBiff8()
Writes the Excel BIFF EXTERNSHEET record. These references are used by formulas.
private
writeExternalsheetBiff8() : string
Return values
stringwriteMsoDrawingGroup()
Writes the MSODRAWINGGROUP record if needed. Possibly split using CONTINUE records.
private
writeMsoDrawingGroup() : string
Return values
stringwriteNumberFormat()
Writes Excel FORMAT record for non "built-in" numerical formats.
private
writeNumberFormat(string $format, int $ifmt) : void
Parameters
- $format : string
-
Custom format string
- $ifmt : int
-
Format index code
writePalette()
Stores the PALETTE biff record.
private
writePalette() : void
writeRecalcId()
Write the RECALCID record.
private
writeRecalcId() : string
Return values
stringwriteSharedStringsTable()
Handling of the SST continue blocks is complicated by the need to include an additional continuation byte depending on whether the string is split between blocks or whether it starts at the beginning of the block. (There are also additional complications that will arise later when/if Rich Strings are supported).
private
writeSharedStringsTable() : string
The Excel documentation says that the SST record should be followed by an EXTSST record. The EXTSST record is a hash table that is used to optimise access to SST. However, despite the documentation it doesn't seem to be required so we will ignore it.
Return values
string —Binary data
writeShortNameBiff8()
Write a short NAME record.
private
writeShortNameBiff8(string $name, int $sheetIndex, array<string|int, array<string|int, int>> $rangeBounds[, bool $isHidden = false ]) : string
Parameters
- $name : string
- $sheetIndex : int
-
1-based sheet index the defined name applies to. 0 = global
- $rangeBounds : array<string|int, array<string|int, int>>
-
range boundaries
- $isHidden : bool = false
Return values
string —Complete binary record data
writeStyle()
Write Excel BIFF STYLE records.
private
writeStyle() : void
writeSupbookInternal()
Write Internal SUPBOOK record.
private
writeSupbookInternal() : string
Return values
stringwriteWindow1()
Write Excel BIFF WINDOW1 record.
private
writeWindow1() : void