开发者

Convert .xlsx file to .csv file using PHP

开发者 https://www.devze.com 2023-03-24 00:46 出处:网络
I\'m looking for a low overhead way to convert a .xlsx file to a .csv file using PHP without consuming excess memory or loading extraneous classes. A开发者_如何学Gonyone?You can read XLSX files with P

I'm looking for a low overhead way to convert a .xlsx file to a .csv file using PHP without consuming excess memory or loading extraneous classes. A开发者_如何学Gonyone?


You can read XLSX files with PHP using PhpSpreadsheet. From there, you only need to figure out the destination format.


You can use following code in PhpSpreadsheet.

$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('CSV');

$objPHPExcel = $reader->load('csv_file.csv');
$objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'XLSX');
$objWriter->save('excel_file.xlsx');

If you need to lower memory usage you can provide some caching to the processing, see - https://phpspreadsheet.readthedocs.io/en/latest/topics/memory_saving/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号