A non-numeric value encountered in phpexel

孤街浪徒 提交于 2020-06-29 20:45:19

问题


Im getting A non-numeric value encountered in xls file when I use Auto filter ,Im using PHPExel package. My opertaing system is ubantu 16.04. Using Libreoffice to view the files.

My code
    <?php
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Date');
    $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Invoice');
    $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Client');
    $row = 2;
    foreach ($values['results'] as $value)
    {
        $objPHPExcel->getActiveSheet()->setCellValue('A'.$row,$columnFilter, date("d-m-Y", strtotime($value->payment_date)));
        $objPHPExcel->getActiveSheet()->setCellValue('B'.$row, $value->invoice_number);
        $objPHPExcel->getActiveSheet()->setCellValue('C'.$row, $value->client_name);

        //Problem in below line when I use auto filter Im getting an non numeric value encountered
        $objPHPExcel->getActiveSheet()->setAutoFilter('A1:C1');
        $row++;
    }
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="Cutomer_Report.xls"');
    header('Cache-Control: max-age=0');
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('php://output');


   Error
   A PHP Error was encountered
   Severity: Warning
   Message: A non-numeric value encountered
   Filename: PHPExcel/Cell.php
   Line Number: 803

回答1:


This is known bug https://github.com/PHPOffice/PHPExcel/issues/1212 To avoid it you can

  1. downgrade php
  2. upgrade to phpspreadsheet
  3. use Excel2007 writer instead of Excel5
  4. try to suppress warning with error_reporting(E_ALL ^ E_WARNING );



回答2:


Like voter said, it's a known bug on the Github and won't be fixed because the developers are focussing on a new library. However, instead of down- and upgrading your environment, you could edit a single line and keep your existing implementation.

As seen in the Github thread:

  1. Go to PHPExcel/Writer/Excel5.php
  2. Around line 372, find $endCoordinates = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::stringFromColumnIndex($iInc - 1));
  3. Change it to only call the function once: $endCoordinates = PHPExcel_Cell::stringFromColumnIndex($iInc - 1);


来源:https://stackoverflow.com/questions/49169679/a-non-numeric-value-encountered-in-phpexel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!