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\Csv; // Read the workbook. Only the values matter for a CSV. $reader = IOFactory::createReaderForFile('products.xlsx'); $reader->setReadDataOnly(true); $spreadsheet = $reader->load('products.xlsx'); // Describe the CSV to write. $writer = new Csv($spreadsheet); $writer->setDelimiter(','); $writer->setEnclosure('"'); $writer->setLineEnding("\r\n"); // Without the BOM, Excel reads UTF-8 as its own legacy encoding. $writer->setUseBOM(true); // A CSV holds one sheet. Pick which one by index. $writer->setSheetIndex(0); $writer->save('products.csv'); $rows = $spreadsheet->getActiveSheet()->getHighestRow(); echo "Done. Converted products.xlsx ($rows rows) to products.csv\n";
The full script from Convert An Excel File To CSV 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 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
Read Large Excel Files In Chunks In PHP Using PHPSpreadSheet
July 22, 2026
Read Formula Results In Excel Files In PHP Using PHPSpreadSheet
July 21, 2026
Browse by technique