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
Unmerge Google Sheets Cells Using Google Sheets API PHP Client
April 22, 2023
What is PHP Excel
April 21, 2023
Merge Google Sheets Cells Using Google Sheets API PHP Client
March 20, 2023
Change Google Sheets Border Using Google Sheets API PHP Client
February 25, 2023
Write Google Sheets Data To A Multiple Range Horizontally Using Google Sheets API PHP Client
August 10, 2022
Write Excel Files Data Horizontally In PHP Using PHPSpreadSheet
July 28, 2022
Merge Cells
July 25, 2022
Write Cell Data Horizontally
July 24, 2022
Write Google Sheets Data To A Single Range Horizontally Using Google Sheets API PHP Client
July 24, 2022
Browse by technique