问题
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
- downgrade php
- upgrade to phpspreadsheet
- use Excel2007 writer instead of Excel5
- 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:
- Go to PHPExcel/Writer/Excel5.php
- Around line 372, find
$endCoordinates = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::stringFromColumnIndex($iInc - 1));
- 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