PhpSpreadsheet is a library used for read, write excel, csv file etc. It is written in PHP language.
It allows us to create, modify, and manipulate spreadsheet documents programmatically.
PHP version 7.2 or newer to develop using PhpSpreadsheet.
To use PhpSpreadsheet, you need to install it in your PHP project. Use composer to install PhpSpreadsheet into your project:
composer require phpoffice/phpspreadsheet
Or also download the documentation and samples if you plan to use them:
composer require phpoffice/phpspreadsheet --prefer-source
This would be the simplest way to write a spreadsheet:
<?php
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');
Format | Reading | Writing |
---|---|---|
Open Document Format/OASIS (.ods) | ✓ | ✓ |
Office Open XML (.xlsx) Excel 2007 and above | ✓ | ✓ |
BIFF 8 (.xls) Excel 97 and above | ✓ | ✓ |
BIFF 5 (.xls) Excel 95 | ✓ | |
SpreadsheetML (.xml) Excel 2003 | ✓ | |
Gnumeric | ✓ | |
HTML | ✓ | ✓ |
SYLK | ✓ | |
CSV | ✓ | ✓ |
PDF (using either the TCPDF, Dompdf or mPDF libraries, which need to be installed separately) | ✓ |