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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用