Reading very large (more than 100MB) Excel files in PHP

一曲冷凌霜 提交于 2020-01-13 09:45:12

问题


I'm trying to read a larger than 100MB Excel file using PHPExcel but it crashes while loading the file. I don't need any styling. I tried using:

$objReader->setReadDataOnly(true);

but it still crashes.

Is there any efficient way to read this size of Excel file in PHP?


回答1:


Try Spout: https://github.com/box/spout.

This is a PHP library that was created to solve your problem (reading/writing large files). Here is why it works:

Other libraries keep a representation of the spreadsheet in memory which make them subject to out of memory errors. Using some caching strategies will help with these kind of errors but will affect performance pretty badly.

On the other hand, Spout uses streams to read or write data. This means that there is only one row kept in memory at all times, all read/written rows being freed from memory. This allows fast read/write of dataset of any size! Give it a try :)



来源:https://stackoverflow.com/questions/33095610/reading-very-large-more-than-100mb-excel-files-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!