LimeSurvey API - Master branch

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.

$firstSheetUsed

private bool $firstSheetUsed = false

Whether the default first worksheet has been used yet.

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.

close()

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
string

sanitizeTitle()

Worksheet titles are limited to 31 characters and may not contain the characters * : / \ ? [ ].

private sanitizeTitle(string $title) : string
Parameters
$title : string
Return values
string

        
On this page

Search results