dtc66318 2016-04-22 20:17
浏览 252
已采纳

PHPExcel:如何读取内容来自其他工作表中单元格的单元格中的值

I have spent the last days trying to solve this issue. I have a spreadsheet with a couple tabs (sheets). The last tab has the values input in all other tabs. Those values are populated automatically by using formulas like:

=$'otherSheetName'.A1

If I leave calculateFormulas = true those values are read as null. If I set calculateFormulas = false the values are read as the literal formula.

I was firstly using LaravelExcel but I gave up from finding a solution for that, so I moved to PHPExcel. Solutions for Laravel Excel will be appreciated too though.

Thanks

Update: How I am reading values in PHPExcel:

$inputFileType = PHPExcel_IOFactory::identify($file->getRealPath());
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setLoadSheetsOnly("MySheet");
$objPHPExcel = $objReader->load($file->getRealPath()); 
$rows = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);

Then, I iterate over the array $rows and extract the values that I want.

  • 写回答

1条回答 默认 最新

  • doutangshuan6473 2016-04-26 07:04
    关注

    You need to load all the dependency sheets that are used in those formulae, though you don't necessarily need to load every worksheet, but can pass a list of sheet names to load as an array

    $objReader->setLoadSheetsOnly(["MySheet", "OtherSheet1", "OtherSheet2"]);
    

    You don't need to iterate over any other worksheets, but can set the active worksheet to whichever sheet you want

    $objReader->setActiveSheetIndexByName("MySheet");
    

    and then any calls to the active sheet ($objPHPExcel->getActiveSheet()->...) to access cells will be a reference to that worksheet.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?