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 WPF动态创建页面内容
  • ¥15 如何对TBSS的结果进行统计学的分析已完成置换检验,如何在最终的TBSS输出结果提取除具体值及如何做进一步相关性分析
  • ¥15 SQL数据库操作问题
  • ¥100 关于lm339比较电路出现的问题
  • ¥15 Matlab安装yalmip和cplex功能安装失败
  • ¥15 加装宝马安卓中控改变开机画面
  • ¥15 STK安装问题问问大家,这种情况应该怎么办
  • ¥15 关于罗技鼠标宏lua文件的问题
  • ¥15 halcon ocr mlp 识别问题
  • ¥15 已知曲线满足正余弦函数,根据其峰值,还原出整条曲线