duanjian4698 2013-08-05 05:17
浏览 61
已采纳

麻烦用PHP解析格式很大的excel文档

I know there are already many questions similar to this one (I have read most of them), but I still haven't found a solution so I figured I'd ask my own question with specifics.

Ok, so I have spent the past two days researching and trying to parse an Excel (.xlsx) spreadsheet in php. I've tried using the PHPExcel Library, however, it times out when trying to load the spreadsheet into memory. The spreadsheet is not very large, only 240kb, but it does have 40+ worksheets each heavily formatted (i.e. cell color, font size/color, etc...). Since I don't need any of the formatting I tried $objReader->setReadDataOnly(true); in order to ignore it, but it still times out when trying to read the file.

So my next step was to try and load only the last couple of worksheets I actually needed using, $objReader->setLoadSheetsOnly(array(42,43,44,45)); This loads successfully, but now the problem is that the last sheets are almost completely formulas which total and read data from the previous worksheets. And since I excluded those earlier worksheets in order to load the document I can't use $cell->getCalculatedValue(); when retrieving each cell's value, thus making everything else obsolete.

So my question is, is there something else I can do in order to load and read this Excel spreadsheet?

Is there another library I should try and use? Or a completely different method I should try, since my end goal is to be able to upload parts of the data to a database?

Here is a link to the particular spreadsheet I am using.

Thanks for taking the time to read this and for any help you can provide.

  • 写回答

2条回答 默认 最新

  • duanhuan8983 2013-08-06 02:00
    关注

    Ok, I figured out why it was taking so long, one partial reason might be I was using an outdated version of PHPExcel, but I believe the real culprit was I had left XDebug enabled from a previous project. Because once I disabled that the script loaded the workbook just fine at a speed of 1.5001 seconds and using 17.5 MB of memory. Thanks for the help guys, it got me looking in the right direction.

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

报告相同问题?

悬赏问题

  • ¥15 在不同的执行界面调用同一个页面
  • ¥20 基于51单片机的数字频率计
  • ¥50 M3T长焦相机如何标定以及正射影像拼接问题
  • ¥15 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)
  • ¥20 关于#stm32#的问题:STM32串口发送问题,偶校验(even),发送5A 41 FB 20.烧录程序后发现串口助手读到的是5A 41 7B A0
  • ¥15 C++map释放不掉
  • ¥15 Mabatis查询数据
  • ¥15 想知道lingo目标函数中求和公式上标是变量情况如何求解
  • ¥15 关于E22-400T22S的LORA模块的通信问题
  • ¥15 求用二阶有源低通滤波将3khz方波转为正弦波的电路