使用 3MB 左右的低内存读取、写入大电子表格,支持格式 CSV、ODS、XLS、XLSX。
Use low memory of around 3MB to read and write large spreadsheets, supporting formats CSV, ODS, XLS, and XLSX.
- PHP version
^7.1
||^8.0
- PHP extension
xml
- PHP extension
libxml
- PHP extension
fileinfo
- PHP extension
simplexml
- PHP extension
xmlreader
- PHP extension
xmlwriter
- PHP extension
iconv
(suggest) - PHP extension
mbstring
(suggest)
composer require chenmobuys/easyexcel
<?php
use EasyExcel\Factory;
use EasyExcel\Metadata\Style;
// read excel
$filename = "/path/to/sample.xlsx";
$reader = Factory::load($filename);
foreach ($reader->getRowIterator() as $row) {
$rowArray = $row->toArray();
}
// write excel
$filename = "/path/to/sample.xlsx";
$writer = Factory::open($filename);
$writer->addRow(["Foo", "Bar"])->close();
// write excel with style
$filename = "/path/to/sample.xlsx";
$writer = Factory::open($filename);
$style = Style::builder()
->setFontSize(12)
->setFontColor(Style\Color::RED)
->build();
$writer->addRow(["Foo", "Bar"], $style)->close();