ExcelWorkbookWriter
in package
Workbook writer compatibility shim.
Drop-in replacement for the subset of the legacy Spreadsheet_Excel_Writer API used by the statistics exporters, backed by PhpSpreadsheet. The output format is XLSX (the legacy library produced the obsolete binary XLS format, which required the abandoned pear/ole package).
Usage mirrors the legacy library:
- new ExcelWorkbookWriter($path) writes to a file on close().
- new ExcelWorkbookWriter() streams to the browser; call send($filename) to set the download headers, then close() to emit the file.
Table of Contents
Constants
- MIME_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
Properties
- $downloadName : string|null
- $filename : string|null
- $firstSheetUsed : bool
- $spreadsheet : Spreadsheet
Methods
- __construct() : mixed
- addFormat() : ExcelCellFormat
- Create a reusable cell format.
- addWorksheet() : ExcelWorksheetWriter
- Add a worksheet and return a writer for it.
- close() : void
- Finalise the workbook: write it to disk or stream it to the browser.
- send() : void
- Register the download file name used when streaming to the browser.
- ensureXlsxExtension() : string
- Ensure the download name uses the .xlsx extension.
- sanitizeTitle() : string
- Worksheet titles are limited to 31 characters and may not contain the characters * : / \ ? [ ].
Constants
MIME_TYPE
public
mixed
MIME_TYPE
= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
Properties
$downloadName
private
string|null
$downloadName
= null
Download file name when streaming to the browser.
$filename
private
string|null
$filename
Target file path when writing to disk.
$firstSheetUsed
private
bool
$firstSheetUsed
= false
Whether the default first worksheet has been used yet.
$spreadsheet
private
Spreadsheet
$spreadsheet
Methods
__construct()
public
__construct([string|null $filename = null ]) : mixed
Parameters
- $filename : string|null = null
-
Optional target file path. When null, the workbook is streamed to the browser.
addFormat()
Create a reusable cell format.
public
addFormat([array<string|int, mixed> $properties = [] ]) : ExcelCellFormat
Parameters
- $properties : array<string|int, mixed> = []
Return values
ExcelCellFormataddWorksheet()
Add a worksheet and return a writer for it.
public
addWorksheet(string $name) : ExcelWorksheetWriter
Parameters
- $name : string
Return values
ExcelWorksheetWriterclose()
Finalise the workbook: write it to disk or stream it to the browser.
public
close() : void
send()
Register the download file name used when streaming to the browser.
public
send(string $filename) : void
The actual headers are emitted by close().
Parameters
- $filename : string
ensureXlsxExtension()
Ensure the download name uses the .xlsx extension.
private
ensureXlsxExtension(string $filename) : string
Parameters
- $filename : string
Return values
stringsanitizeTitle()
Worksheet titles are limited to 31 characters and may not contain the characters * : / \ ? [ ].
private
sanitizeTitle(string $title) : string
Parameters
- $title : string