使用PHPExcel读取多个文件

使用PHPExcel读取多个文件

本文介绍了使用PHPExcel读取多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近才开始使用该库(来自CodePlex的库),但是遇到了一些问题.我的目标是使用它,以便可以处理来自多个Excel文件的某些数据,并将每个文件的此类数据发送到数据库.我正在做类似的事情:

I just recently started using this library (the one from CodePlex), but I ran into some issues. My goal is to use it so I can process some data from multiple Excel files, and send such data to a database, per file. I'm doing something like:

foreach( $file_list as $file ) {

    $book = PHPExcel_IOFactory::load( $path . $file );

}

所以,在foreach中,我现在(现在)只是向用户显示数据,但是在五个文件之后,出现内存错误:

So, inside the foreach I'm (for now) just showing the data to the user, but after five files, I get a memory error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 50688 bytes) in /var/www/test/classes/PHPExcel/Shared/OLERead.php on line 76

是否有一种方法可以在装入每个文件后__destruct对象,因此为下一个文件保留(腾出)空间,而不是对其进行累加,还是您知道原因和解决方法?

Is there a way to __destruct the object after each file is loaded, so space is reserved (made free) for the next file, instead of accumulating it, or do you rather know of a reason and work-around for this?

请让我知道您有任何建议.

Please let me know any suggestions you have.

谢谢.

推荐答案

PHPExcel的最新SVN代码(今天已检查)引入了单元缓存以减少内存使用...这是一个新功能,我什至没有尚有时间进行记录.尽管默认方法与本方法相同,但工作表<->单元关系包含循环引用,但我认为使用任何减少内存的缓存机制都应消除该循环引用.如果没有,请告诉我,并且在使用序列化用于缓存的单元格时已经使用一些已禁用此连接的缓存逻辑来取消工作簿/工作表时,应该可以断开引用.

The latest SVN code for PHPExcel (just checked in today) introduces cell caching to reduce memory usage... it's such a new feature, I haven't even had the time to document it yet.While the default method is identical to the present method, with the worksheet <--> cell relationship containing a cyclic reference, I believe that using any of the memory-reducing cache mechanisms should eliminate this cyclic reference. If not, let me know and I should be able to break the reference when unsetting a workbook/worksheet using some of the caching logic that already disables this connection when serializing the cells for caching.

这篇关于使用PHPExcel读取多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 18:42