Friday 15 May 2015

php - PHPExcel array_filter() error -



php - PHPExcel array_filter() error -

i using phpexcel generate excel document off of template have. thought database update template, maintaining current format, , pass file user download.

the problem when seek , (using basic practice code, shown below) next 3 errors:

warning: array_filter() expects parameter 1 array, null given in d:\web\htdocs\dew\root\welsh\scorecard\classes\phpexcel\worksheet\autofilter.php on line 663 warning: array_filter() expects parameter 1 array, null given in d:\web\htdocs\dew\root\welsh\scorecard\classes\phpexcel\worksheet\autofilter.php on line 664 warning: array_filter() expects parameter 1 array, null given in d:\web\htdocs\dew\root\welsh\scorecard\classes\phpexcel\worksheet\autofilter.php on line 665

lines 663-665 in autofilter.php

$arguments['date'] = array_filter($arguments['date']); $arguments['time'] = array_filter($arguments['time']); $arguments['datetime'] = array_filter($arguments['datetime']);

my test code:

<?php require('/classes/phpexcel/iofactory.php'); $objphpexcel = new phpexcel(); $objphpexcel = phpexcel_iofactory::load("test.xlsx"); $objphpexcel->getactivesheet()->setcellvalue('f8','yes_it_worked'); $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel2007'); $objwriter->save("test2.xlsx"); ?>

now, when code finished running, generate xlsx document. however, document has bulk of cells hidden. first row visible, rows between 1 , 86 hidden.

the next found solve problem:

the excel document using has lot of filters , odd excel-specific formatting. phpexcel may not have been able handle of these conditions, theory. telling code autofilter excel document fixed issue me, such follows:

<?php require('/classes/phpexcel/iofactory.php'); $objphpexcel = new phpexcel(); $objphpexcel = phpexcel_iofactory::load("test.xlsx"); $objphpexcel->getactivesheet()->setcellvalue('f8','yes_it_worked'); $objphpexcel->getactivesheet()->setautofilter($objphpexcel->getactivesheet()->calculateworksheetdimension()); $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel2007'); $objwriter->save("archives/test2.xlsx"); ?>

amphetamachine's reply taught me this alter in autofilter.php fixes problem (see answer, below).

the warnings caused phpexcel 1.8.0 not initializing array indexes before using them. in order rid of them, apply this patch:

class="lang-diff prettyprint-override">diff -ru pex.orig/classes/phpexcel/worksheet/autofilter.php pex/classes/phpexcel/worksheet/autofilter.php --- pex.orig/classes/phpexcel/worksheet/autofilter.php 2014-03-02 15:27:06.000000000 -0600 +++ pex/classes/phpexcel/worksheet/autofilter.php 2014-11-11 15:34:53.582219599 -0600 @@ -634,6 +634,9 @@ } else { // filter on date grouping values $arguments = array(); + $arguments['date'] = array(); + $arguments['time'] = array(); + $arguments['datetime'] = array(); foreach($ruledataset $rulevalue) { $date = $time = ''; if ((isset($rulevalue[phpexcel_worksheet_autofilter_column_rule::autofilter_ruletype_dategroup_year])) &&

php phpexcel

No comments:

Post a Comment