|
1 |
| -# php-xslx-fast-editor |
2 |
| -PHP library to make basic and fast read-write operations on existing Excel workbooks |
| 1 | +# php-xlsx-fast-editor |
| 2 | + |
| 3 | +PHP library to make basic and fast read-write operations on existing Excel workbooks. |
| 4 | + |
| 5 | +It handles XLSX/XLSM documents (Microsoft Excel 2007+, Office Open XML Workbook) using fast and simple low-level ZIP & XML manipulations, |
| 6 | +without requiring any library dependency. |
| 7 | + |
| 8 | +## Rationale |
| 9 | + |
| 10 | +If you need advanced manipulation of Excel documents such as working with formulas and styles, |
| 11 | +check the [PhpSpreadsheet](https://github.com/PHPOffice/PhpSpreadsheet) library |
| 12 | +(previously [PHPExcel](https://github.com/PHPOffice/PHPExcel/)), |
| 13 | +but for simply reading & writing basic values from existing Excel workbooks, `PhpSpreadsheet` is over an order of magnitude too slow. |
| 14 | + |
| 15 | +There are also libraries to create new Excel documents from scratch, or for just reading some values, but not any obvious one for editing. |
| 16 | + |
| 17 | +`php-xlsx-fast-editor` addresses the need of quickly reading and writing & editing existing Excel documents. |
| 18 | + |
| 19 | +## Examples |
| 20 | + |
| 21 | +```php |
| 22 | +// Use composer or load manually: |
| 23 | +require 'vendor/alexandrainst/XlsxFastEditor/autoload.php'; |
| 24 | +use alexandrainst\XlsxFastEditor\XlsxFastEditor; |
| 25 | + |
| 26 | +$xlsxFastEditor = new XlsxFastEditor('test.xlsx'); |
| 27 | + |
| 28 | +$worksheetId1 = $xlsxFastEditor->getWorksheetNumber('Sheet1'); |
| 29 | +$worksheetId2 = $xlsxFastEditor->getWorksheetNumber('Sheet2'); |
| 30 | + |
| 31 | +echo $xlsxFastEditor->readFloat($worksheetId1, 'B2'), "\n"; |
| 32 | +echo $xlsxFastEditor->readInt($worksheetId1, 'C3'), "\n"; |
| 33 | +echo $xlsxFastEditor->readString($worksheetId2, 'D4'), "\n"; |
| 34 | + |
| 35 | +// If you want to force Excel to recalculate formulas on next load: |
| 36 | +$xlsxFastEditor->setFullCalcOnLoad($worksheetId2, true); |
| 37 | + |
| 38 | +$xlsxFastEditor->writeFloat($worksheetId1, 'B2', 3.14); |
| 39 | +$xlsxFastEditor->writeInt($worksheetId1, 'C3', 13); |
| 40 | +$xlsxFastEditor->writeString($worksheetId2, 'D4', 'Hello'); |
| 41 | + |
| 42 | +// Regex search & replace operating globally on all the worksheets: |
| 43 | +$xlsxFastEditor->textReplace('/Hello/i', 'World'); |
| 44 | + |
| 45 | +$xlsxFastEditor->save(); |
| 46 | +// If you do not want to save, call `close()` instead: |
| 47 | +// $xlsxFastEditor->close(); |
| 48 | +``` |
| 49 | + |
| 50 | +## Requirements |
| 51 | + |
| 52 | +PHP 7.4+ with ZIP and XML extensions. |
| 53 | +Check [`composer.json`](./composer.json) for details. |
| 54 | + |
| 55 | +## Credits |
| 56 | + |
| 57 | +Originally written by [Alexandre Alapetite](https://github.com/Alkarex) for the [Alexandra Institute](https://alexandra.dk/), 2023. |
| 58 | +License [GNU AGPL](https://gnu.org/licenses/agpl.html). |
0 commit comments