xlswriter 是一个 PHP C 扩展,可用于在 Excel 2007+ XLSX 文件中读取数据,插入多个工作表,写入文本、数字、公式、日期、图表、图片和超链接。
它具备以下特性:
测试环境: Macbook Pro 13 inch, Intel Core i5, 16GB 2133MHz LPDDR3 Memory, 128GB SSD Storage.
两种内存模式导出 100 万行数据(每行 27 列,数据类型均为字符串,单个字符串长度为 19 )
29S
,内存只需2083MB
;52S
,内存仅需<1MB
;100 万行数据(单行 1 列,数据类型为 INT )
3S
,内存仅558MB
;2.8S
,内存仅<1MB
;$excel = new \Vtiful\Kernel\Excel(['path' => './tests']); $filePath = $excel->fileName('tutorial.xlsx', 'TestSheet1') ->header(['String', 'Int', 'Double']) ->data([ ['Item_1', 10, 10.9999995], ]) ->output(); // 写入方式打开,将文件指针指向文件末尾。 $fp = fopen('./tests/file.csv', 'a'); // 将 xlsx 文件写入 CSV $resultBoolOne= $excel->openFile('tutorial.xlsx') ->openSheet() ->putCSV($fp); // 将 xlsx 文件追加写入 CSV $resultBoolTwo = $excel->openFile('tutorial.xlsx') ->openSheet() ->putCSV($fp);
String,Int,Double Item_1,10,10.9999995 String,Int,Double Item_1,10,10.9999995
应用场景与常规模式类似,不同之处在于上层业务可以在回调函数中加工数据,将 xlsx 中的数据过滤加工并写入 csv。
Github:https://github.com/viest/php-ext-excel-export
Gitee:https://gitee.com/viest/php-ext-xlswriter
PECL:https://pecl.php.net/package/xlswriter
https://xlswriter-docs.viest.me
最后的最后请不要忘记 star
![]() | 1 codespots 2019-12-27 11:43:30 +08:00 不错,点赞 |
![]() | 2 U7Q5tLAex2FI0o0g 2019-12-27 11:52:30 +08:00 看起来很不错的样子 |
![]() | 3 zhs227 2019-12-27 12:31:32 +08:00 很强大,文档也做的很好看。 |
4 sunorg 2019-12-27 12:36:20 +08:00 贡献了第一个 star,跟抢到了第一个沙发一样爽 |