用PHP读取非常大(超过100MB)的Excel文件 [英] Reading very large (more than 100MB) Excel files in PHP

查看:1413
本文介绍了用PHP读取非常大(超过100MB)的Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHPExcel读取大于100MB的Excel文件,但是在加载文件时崩溃.我不需要任何样式.我尝试使用:

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);

但是它仍然崩溃.

有什么有效的方法可以在PHP中读取此大小的Excel文件?

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

推荐答案

尝试水嘴: https://github.com/box/spout .

这是一个为解决您的问题(读取/写入大文件)而创建的PHP库.这是它起作用的原因:

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.

另一方面,Spout使用流来读取或写入数据.这意味着内存始终只保留一行,所有读/写的行都从内存中释放出来.这样可以快速读取/写入任意大小的数据集!试试看:)

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 :)

这篇关于用PHP读取非常大(超过100MB)的Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆