开发者

Convert .xlsx file to .csv file using PHP

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜