Every article in this section solves the same shape of problem: a spreadsheet that has to be produced, parsed or converted by a program rather than by a person. The language is PHP, the library is PhpSpreadsheet, and none of it needs Excel installed on the server.
Start here
If you have not used the library before, three articles cover the whole loop — pull it in with Composer, write a file, read one back.
Formatting and page layout
The largest group of articles here. Fonts, colours, borders, number formats, alignment and text wrapping, then the conditional formatting layer — data bars, colour scales and icon sets. Separately, everything that only matters once the file gets printed: margins, orientation, headers and footers, repeating rows and an explicit print area.
Formulas
PhpSpreadsheet writes a formula as a string and Excel evaluates it when the file opens, which is fine right up until you need the answer inside PHP instead. Both directions are covered:
Getting data in and out
Converting between formats is most of the real work. The workbook is rarely the destination — it is the thing standing between a database and a person.
- Excel to JSON, to CSV, to an HTML table, to XML and to PDF
- The database round trip: import a workbook into MySQL and export a query back out
- Send the finished file to the browser and handle one a user uploaded
Need a one-off conversion rather than code? The converter does it in the browser, without uploading your file anywhere.
Big files and untrusted input
A workbook someone uploaded is input like any other, and an .xlsx is a zip full of XML. Read large files in chunks to stay inside the memory limit, prevent formula injection on the way out, and guard against XXE on the way in.
Snippets
Short single-task recipes for when you only want the two lines that merge cells, add a border or rename a sheet. Browse the snippets.
Working in Google Sheets instead?
The same jobs against a live spreadsheet rather than a file on disk are on the Google Sheets side. The two overlap more than they look: the cell model is the same, only the transport differs.