Basic Hello World Example
This example demonstrates the simplest way to create a spreadsheet with PhpSpreadsheet. We’ll create a new spreadsheet, add some data to cells, and save it to a file.What This Code Does
- Creates a new spreadsheet:
new Spreadsheet()initializes an empty spreadsheet with one worksheet - Sets cell values: Uses
setCellValue()to add text to specific cells (A1, B2, C1, D2) - Renames the worksheet: Changes the default sheet name from “Worksheet” to “Simple”
- Saves the file: Creates an Xlsx writer and saves the spreadsheet as
hello_world.xlsx
Adding UTF-8 Characters
PhpSpreadsheet fully supports UTF-8 characters, allowing you to work with international text:Multi-line Text in Cells
You can add multi-line text to cells by using newline characters (\n) and enabling text wrapping:
Key Takeaways
- Always require the autoloader before using PhpSpreadsheet classes
- Use
setCellValue()to add data to cells - Cell references use Excel notation (A1, B2, etc.)
- Method chaining is supported for cleaner code
- Save files using writer classes like
Xlsx,Xls, orOds

