draj30958 2010-04-23 17:57
浏览 122
已采纳

使用PHPExcel读取多个文件

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

}

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

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.

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • douxia2053 2010-04-23 20:26
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分