PHPSpreadsheet · Google Sheets API · Excel
Spreadsheets, driven by code.
Hands-on PHP tutorials for working with Excel and Google Sheets — read and
write .xlsx, convert files to JSON, stream downloads in the
browser, and insert images, formulas, and styling. Every guide ships with
code you can copy, run, and adapt.
Latest complete code
<?php require 'vendor/autoload.php'; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\Style\Color; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); // Build the rich-text value out of separate runs. $rich = new RichText(); $rich->createText('Order #1024 '); $overdue = $rich->createTextRun('OVERDUE'); $overdue->getFont()->setBold(true); $overdue->getFont()->setColor(new Color(Color::COLOR_RED)); $rich->createText(' — pay within 14 days'); // Drop the whole RichText object into one cell. $worksheet->setCellValue('A1', $rich); $writer = new Xlsx($spreadsheet); $writer->save('rich-text.xlsx'); echo "Wrote rich-text.xlsx\n";
The full script from Add Rich Text To A Single Cell In Excel Files In PHP Using PHPSpreadSheet — copy, run, adapt.
Key methods
IOFactory::load()
PhpSpreadsheet
getActiveSheet()
PhpSpreadsheet
fromArray()
PhpSpreadsheet
getCalculatedValue()
PhpSpreadsheet
save('php://output')
PhpSpreadsheet
spreadsheets_values->get()
Google Sheets
spreadsheets_values->update()
Google Sheets
spreadsheets->create()
Google Sheets
json_encode()
PHP
header()
PHP
Latest articles
Add Rich Text To A Single Cell In Excel Files In PHP Using PHPSpreadSheet
August 2, 2026
List The Worksheets In An Excel File In PHP Using PHPSpreadSheet
August 1, 2026
Convert An Excel File To An HTML Table In PHP Using PHPSpreadSheet
July 31, 2026
Loop Through Cells With Iterators In PHP Using PHPSpreadSheet
July 30, 2026
Convert An Excel File To CSV In PHP Using PHPSpreadSheet
July 29, 2026
Handle An Uploaded Excel File In PHP Using PHPSpreadSheet
July 28, 2026
Convert An Excel File To PDF In PHP Using PHPSpreadSheet
July 27, 2026
Freeze The Header Row In Excel Files In PHP Using PHPSpreadSheet
July 26, 2026
Create An Excel Chart In PHP Using PHPSpreadSheet
July 25, 2026
Browse by technique