This section covers Excel at two levels. Formulas are the sheet’s own language — code that lives in a cell and runs with nothing installed and no project to set up. PhpSpreadsheet is the level above: a spreadsheet produced, parsed or converted by a program rather than by a person, in PHP, without Excel installed on the server. Most real work starts in a cell and moves up only when it has to.
Formulas: code that lives in a cell
No project, no credentials, nothing installed — these run in the workbook itself. Modern Excel has a set of functions that reshape, slice and combine whole ranges at once, and most of them have no Google Sheets equivalent at all.
- Split a text column with TEXTSPLIT — and TEXTBEFORE, TEXTAFTER, without Text to Columns
- Combine ranges with VSTACK and HSTACK instead of copy and paste
- Flatten a grid with TOCOL and TOROW
- Slice a range with TAKE, DROP and CHOOSECOLS, counting from either end
- Generate a grid with SEQUENCE rather than filling one down
Alongside those sit short one-function cards — CONCAT, TRIM, IF, SUMIF, DATEDIF and the rest — each with the one behaviour that trips people up.
The ceiling is real. A formula recalculates when the workbook does, not when you say so; it cannot read a database, authenticate, retry, or write a file anywhere; and it only exists inside a workbook somebody has open. When any of that starts to matter, the rest of this page is the level to move to.
Browse every Excel formula article
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 from PHP
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.