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\IOFactory; use \PhpOffice\PhpSpreadsheet\Writer\Html; // Load the workbook, keeping styles so the HTML can carry them. $spreadsheet = IOFactory::load('sales.xlsx'); $writer = new Html($spreadsheet); // Write every sheet, not just the active one. $writer->writeAllSheets(); // Put the CSS on each element instead of in a <style> block, so the // table survives being pasted into a page or an email. $writer->setUseInlineCss(true); // A whole HTML document: <html>, <head>, the styles, and the tables. $writer->save('sales.html'); // Just the <table> markup, for dropping into a page you already have. $writer->setSheetIndex(0); $tableOnly = $writer->generateSheetData(); file_put_contents('table-only.html', $tableOnly); echo 'Done. Wrote sales.html (' . strlen(file_get_contents('sales.html')) . " bytes, all sheets)\n"; echo 'and table-only.html (' . strlen($tableOnly) . " bytes, the table markup alone).\n";
The full script from Convert An Excel File To An HTML Table 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
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
Work With Multiple Worksheets In Excel Files In PHP Using PHPSpreadSheet
July 24, 2026
Convert A CSV File To Excel In PHP Using PHPSpreadSheet
July 23, 2026
Browse by technique