dry18813 2014-06-09 06:43
浏览 162
已采纳

PHPExcel excel读取不适用于某些计算单元格

I use PHPExcel lib for read the excel file in Codeigniter project. It is not read some cells with calculation. It show as #VALUE! But some values with calculation is reading in same excel sheet. Whats wrong with those cells?

Cells with have following calculation is not reading

=+D109*1000     
=+B16/B13
=+D23/$D$109 

Cells with have following calculation is reading

=+B10-B11
=+C10-C11

But all cells are reading for some excel sheet. This issue come with xlsx format

This is my code

$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$this->excel = $objReader->load($path);
$this->excel->setActiveSheetIndex($sheet);
$data = $this->excel->getActiveSheet()->toArray(null, true, true, true);

print_r($data);

I check with google. getCalculatedValue() should use for read calculated values. But i can't use it one by one. Is it has a method to read all sheet as array?

How ever i checked some cells with following way

$this->excel->getActiveSheet()->getCell('B18')->getCalculatedValue() // return #VALUE!
$this->excel->getActiveSheet()->getCell('B18')->getOldCalculatedValue() //return 0.4211

How i use old calculated value using toArray?

  • 写回答

1条回答 默认 最新

  • doxrxwn2252 2014-07-10 11:18
    关注

    Finally I get old getOldCalculatedValue using loop.

    $data = $this->excel->getActiveSheet()->toArray(null, true, true, true);
    
    //This code add for some calculated cells were not reading in xlsx format
    foreach ($data as $no => $row) {
        foreach ($row as $key => $value) {
            if (isset($value) && $value == '#VALUE!') {
                $data[$no][$key] = $this->excel->getActiveSheet()->getCell($key.$no)->getOldCalculatedValue();
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助