xlswriter

Efficient and fast xlsx file extension.


xlswriter is a PHP C Extension that can be used to write text, numbers, formulas and hyperlinks to multiple worksheets in an Excel 2007+ XLSX file.

Writer

- 100% compatible Excel XLSX files.
- Full Excel formatting.
- Merged cells.
- Defined names.
- Autofilters.
- Charts.
- Data validation and drop down lists.
- Worksheet PNG/JPEG images.
- Memory optimization mode for writing large files.
- Works on Linux, FreeBSD, OpenBSD, OS X, Windows.
- Compiles for 32 and 64 bit.
- FreeBSD License.
- The only dependency is on zlib.

Reader

- Full read data
- Cursor read data
- Read by data type
- Xlsx to csv

License: BSD license

Latest releases

Version Release Download
3.0.0 2026-07-05 xlswriter-3.0.0.tgz
2.0.3 2026-06-14 xlswriter-2.0.3.tgz
2.0.2 2026-06-03 xlswriter-2.0.2.tgz
2.0.1 2026-05-25 xlswriter-2.0.1.tgz
2.0.0 2026-05-16 xlswriter-2.0.0.tgz
Show all releases

Changelog

Version Message
3.0.0 - Feature: formula calculation. evaluateFormula(string $formula) evaluates an Excel formula and returns its result — operator precedence and arithmetic, cell and range references (A1, A1:A3) resolved against the values already written, aggregates (SUM / AVERAGE / MIN / MAX / COUNT / COUNTA), and logical/text functions (IF, CONCATENATE, UPPER, LEN, ...), with Excel error values (#DIV/0!, #NUM!, ...) surfaced as strings. computeFormula(bool $enable = true) opts the workbook into caching, so insertFormula() writes the computed result into the file and other readers see the value without recalculating.
- Feature: round-trip editing of an existing workbook. openFile() a saved .xlsx and change it in place — cell values, styles, merged ranges, dates and sheet dimensions — add new worksheets, and insert images and charts into the opened workbook, then output() the result. The existing write methods (insertText / insertImage / insertChart / mergeCells / setRow / addSheet, ...) work unchanged in edit mode; unsupported edit operations are now reported instead of being silently dropped.
- Performance: normal-mode (non constant_memory) export is about 27% faster with roughly 18% lower peak memory; the constant_memory streaming path gained an integer fast-path that skips float formatting for whole-number cells.
- Fix: the reader returned 0 for negative or zero decimals read through nextCellCallback (the numeric branch was selected on the sign of the value instead of its parsed type); negative and fractional values now read back correctly.
- Fix: locale independence. Numbers are written and parsed with a '.' decimal point regardless of the host LC_NUMERIC, so using the extension under a ','-decimal locale (for example after setlocale(LC_ALL, 'de_DE')) no longer corrupts written values or misreads cell values, row heights, column widths and font sizes.
- Fix: the formula engine is hardened against malformed or hostile input passed to evaluateFormula — deeply nested or over-long expressions can no longer overflow the stack, and an oversized range aggregate such as SUM(A1:XFD1048576) returns #NUM! instead of hanging.
- Fix: numerous memory-safety and robustness corrections across the reader, the edit path and XML output, including NULL-dereference guards on allocation failure.
- Note: 3.0.0 is a major release — the reader and writer now share a single unified core alongside the new formula and round-trip editing engines above. All existing class methods, signatures and Excel::* / Format::* constant values are unchanged, so upgrading requires no code changes.
2.0.3 - Feature: autoSize(?string $range = null) sizes columns to fit their content. Column widths are estimated from the written cell values (wide/CJK code points count as two columns) and applied at output() time. Tracking is opt-in (call autoSize() before the writes it should size), so writes that never use it pay no per-cell cost; widths are clamped to Excel's 255 max (#305 / #514).
- Performance: worksheet metadata (merges, hyperlinks, protection, row/col options) is now loaded lazily instead of eagerly at openSheet(), so data-only reads (getSheetData / nextRow / nextCellCallback / putCSV) skip the second full XML pass — about 40% faster on large sheets.
- Performance: merge-follow lookups (SKIP_MERGED_FOLLOW) are indexed by last_row with a forward cursor, turning the per-cell scan from O(cells × merges) into amortised near-O(1).
- Fix: RichString leaked one zend_string per instance (the constructor's zend_string_copy was never released) and its fetch-object offset pointed at the wrong struct; both corrected.
- Fix: the cell/row-end/image/comment/chart callback bridges no longer zval_ptr_dtor an uninitialised return value when a callback throws or the call fails.
- Fix: xlsx_to_csv leaked its temp row on the write-failure path; openFile() now resets reader bookkeeping the way openSheet() and the dtor do; fileName()/constMemory() handle workbook/worksheet allocation failure instead of dereferencing NULL.
- Fix: the reader now reads every image from drawing.xml instead of stopping after the first 64 KB.
- Fix: PHP 8.6 compatibility — XtOffsetOf replaced with the standard offsetof, and zval_dtor with zval_ptr_dtor_nogc.
- Fix: setColumn()/setRow() leaked the per-call row/col options struct, and insertImage() leaked the path zend_string (#573).
2.0.2 - Feature: insertImageOpt($row, $col, $path, $options) adds pixel-precise x_offset / y_offset within the anchor cell, scale via width/height, a "don't move or size with cells" anchor mode, plus mouseover tip, alt text (description / decorative) and a hyperlink overlay. Object positioning is exposed through new Excel::OBJECT_POSITION_* constants. The original insertImage() signature is untouched (#357 / #437 / #473 / #297 / #449).
- Feature: insertDynamicFormula() and insertDynamicArrayFormula() emit the t="array" + ref-range XML that Excel 365 dynamic array functions (UNIQUE, FILTER, SORT, SEQUENCE, XLOOKUP, etc.) require, which insertFormula() does not produce (#503).
- Feature: outlineSettings(bool $visible = true, bool $below = true, bool $right = true, bool $autoStyle = false) configures worksheet outline (grouping) display (#540).
- Fix: PHP true/false passed to writeSheet / data now writes a real boolean cell (xlsx type="b") via worksheet_write_boolean; previously bool fell through type_writer() silently and the cell was emitted as blank (#543).
2.0.1 - Fix: insertDate / insertText with $format string now caches each distinct format on its own cache slot; previously ZEND_STRL on a zend_string flexible-array key collapsed every format into one entry, so the first format won and every subsequent call returned the wrong cached format (#552 / #548 / #544).
- Fix: format_copy() now carries font_name (and font_scheme / has_font / has_dxf_font), so a Format resource passed alongside a num-format string keeps the caller's font() instead of falling back to Calibri (#545 / #472).
- Fix: data-validation inline list now rejects with an exception when the joined CSV exceeds Excel's 255-character spec limit, instead of overflowing libxlsxwriter's fixed-size buffer (#486 / #530 / #546).
- Fix: header() called after data() throws instead of silently overwriting the first data row (#535).
- Fix: empty-string sheet name is rejected up-front instead of producing an xlsx that Excel can't open (#528).
- Fix: outline-level warnings in setColumn / setRow / defaultRowOptions use %ld instead of %d so the build no longer fails on Alpine 3.22 + gcc 14 hardening defaults (#556).
- Build: tests + examples now parse on PHP 7.0 (the declared minimum); CI matrix expanded to PHP 7.0-7.3 on ubuntu-22.04 (#565).
- Build: composer.json declares download-url-method=pre-packaged-source so `pie install viest/xlswriter` fetches the self-contained xlswriter-(version).tgz attached to the GitHub release instead of the submodule-less packagist zipball.
2.0.0 - Refactor: replaced libxlsxio dependency with the in-tree libxlsxreader (PHP-agnostic C library, lives under library/libxlsxreader/).
- Reader: shared-strings table now supports both FULL and STREAMING modes; FSM-driven worksheet parser with 64KB XML buffer; honors 1900 vs 1904 date systems via workbook.xml.
- Reader: PHP API (openFile/openSheet/nextRow/nextCellCallback/getSheetData/setType/setGlobalType/setSkipRows/putCSV/putCSVCallback) is fully backward compatible.
- Reader: surface sheet-level metadata — getMergedCells, getHyperlinks, getSheetProtection, getRowOptions/getColumnOptions, getDefaultRowHeight/getDefaultColumnWidth, getDefinedNames, sheetListWithMeta.
- Reader: surface page setup, rich-text runs, comments, charts, and conditional formats — getPageSetup, nextRowRich, iterateImages, iterateComments, iterateCharts, getConditionalFormats.
- Reader: full formula attributes (next-row-with-formula), data validations (getDataValidations), autofilter (getAutoFilter); new static helper Excel::getFormulaAst() for tokenizing formulas without evaluation.
- Reader: getStyleFormat resolves a style id to a rich array of font/fill/border/alignment/protection.
- Writer: conditional formats (Vtiful\Kernel\ConditionalFormat + conditionalFormatCell/Range).
- Writer: Excel tables (Vtiful\Kernel\Table + addTable).
- Writer: page setup — setHeader/setFooter, repeatRows/repeatColumns, printArea, horizontalPageBreaks/verticalPageBreaks, fitToPages, setTabColor.
- Writer: workbook properties — setProperties, setCustomProperty.
- Writer: defined names — defineName (workbook- and sheet-scoped).
- Writer: insertCommentOpt, insertImageBuffer, setBackgroundImage/Buffer, insertRichText.
- Format: borderColorOfTheFourSides, borderOfTheFourSides, indent, rotation, locked/unlocked/hidden cell protection.
- Fix: setBackgroundImage / setBackgroundImageBuffer now bundle the referenced media inside the xlsx (the sheet's picture relationship pointed at a media file that was never written).
- Fix: setHeader/setFooter with image_left/image_center/image_right options now produces a valid xlsx (header VML drawing and content-type registration were missing, making the output unopenable).
- New constants: Excel::COMMENT_DISPLAY_DEFAULT / HIDDEN / VISIBLE so insertCommentOpt(['visible' => …]) callers don't have to guess libxlsxwriter's lxw_comment_display enum.
- Build: feature-flagged reader (--disable-reader produces a write-only build); minizip is shared between writer and reader.
- Update libxlsxwriter from 1.1.3 to 1.1.6.
Show complete changelog