PHP extension for reading and writing Excel files (XLS and XLSX) using the LibXL library.
- PHP 8.3+
- LibXL 4.6.0+ (commercial library)
| Class | Description |
|---|---|
| ExcelBook | Workbook management: create, load, save, sheets, fonts, formats, pictures |
| ExcelSheet | Cell read/write, formatting, printing, protection, hyperlinks, data validation |
| ExcelFormat | Cell formatting: colors, borders, number formats, alignment, patterns |
| ExcelFont | Font properties: name, size, bold, italic, underline, color |
| ExcelAutoFilter | AutoFilter operations and sorting |
| ExcelFilterColumn | Filter column criteria |
| ExcelRichString | Mixed-font text in a single cell |
| ExcelFormControl | Form controls: checkboxes, dropdowns, spinners, buttons |
| ExcelConditionalFormat | Conditional formatting style rules |
| ExcelConditionalFormatting | Conditional formatting ranges and rule application |
| ExcelCoreProperties | Workbook metadata: title, author, dates, categories |
| ExcelTable | Structured table support (xlsx) |
Via PIE:
pie install iliaal/php-excel \
--with-libxl-incdir=/path/to/libxl/include_c \
--with-libxl-libdir=/path/to/libxl/lib64Or manually:
phpize
./configure --with-excel \
--with-libxl-incdir=/path/to/libxl/include_c \
--with-libxl-libdir=/path/to/libxl/lib64
make
make installAdd extension=excel.so to your php.ini.
<?php
$book = new ExcelBook(null, null, true); // xlsx mode
$book->setLocale('UTF-8');
$sheet = $book->addSheet('Sheet1');
$data = [
[1, 1500, 'John', 'Doe'],
[2, 750, 'Jane', 'Doe'],
];
$row = 1;
foreach ($data as $item) {
$sheet->writeRow($row++, $item);
}
// formula
$sheet->write($row, 1, '=SUM(B1:B3)');
// date with format
$dateFormat = new ExcelFormat($book);
$dateFormat->numberFormat(ExcelFormat::NUMFORMAT_DATE);
$sheet2 = $book->addSheet('Sheet2');
$sheet2->write(1, 0, (new DateTime('2024-08-02'))->getTimestamp(), $dateFormat, ExcelFormat::AS_DATE);
$book->save('output.xlsx');Store credentials in php.ini instead of source code. The extension reads them automatically when you pass null to the constructor.
[excel]
excel.license_name="YOUR_LICENSE_NAME"
excel.license_key="YOUR_LICENSE_KEY"
excel.skip_empty=0See the docs/ directory for API reference and the tests/ directory for usage examples.