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; $inputFile = 'workbook.xlsx'; $reader = IOFactory::createReaderForFile($inputFile); // The names alone. This does not load a single cell. $names = $reader->listWorksheetNames($inputFile); echo "Sheets in {$inputFile}:\n"; foreach ($names as $i => $name) { echo " [{$i}] {$name}\n"; } // One entry per sheet, with its dimensions - still without loading the cells. echo "\nSize of each sheet:\n"; foreach ($reader->listWorksheetInfo($inputFile) as $info) { printf( " %-10s %5d rows x %2d cols (last cell %s%d)\n", $info['worksheetName'], $info['totalRows'], $info['totalColumns'], $info['lastColumnLetter'], $info['totalRows'] ); } // Load ONLY the sheet you want. The reader skips everything else as it parses. $reader->setLoadSheetsOnly('Notes'); $spreadsheet = $reader->load($inputFile); printf( "\nLoaded only 'Notes': %d sheet in memory (%s), %.2f MB peak.\n", $spreadsheet->getSheetCount(), implode(', ', $spreadsheet->getSheetNames()), memory_get_peak_usage(true) / 1048576 );
The full script from List The Worksheets In An Excel File 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
Create Excel Files With Rows And Columns Repeat Settings In PHP Using PHPSpreadSheet
July 26, 2020
Create Excel Files With Option To Hide The Gridlines In PHP Using PHPSpreadSheet
July 25, 2020
Create Excel Files With Printing Breaks Settings In PHP Using PHPSpreadSheet
July 19, 2020
Create Excel Files With Header And Footer In PHP Using PHPSpreadSheet
July 18, 2020
Create Excel Files With Center On Page Settings In PHP Using PHPSpreadSheet
July 18, 2020
Create Excel Files With Page Margins Settings In PHP Using PHPSpreadSheet
July 18, 2020
Create Excel Files With Page Orientation And Paper Size Settings In PHP Using PHPSpreadSheet
July 18, 2020
Create Excel Files With Explicit Cell Datatype In PHP Using PHPSpreadSheet
July 12, 2020
Create Excel Files With Line Breaks In PHP Using PHPSpreadSheet
July 12, 2020
Browse by technique