php - Issue with Countifs in PHPExcel when generating a PDF -


i have problem phpexcel , can’t seem find solution fix it. wrote script based on basic examples provided in phpexcel documentation create pdf file out of xlsx file code looks this:

$inputfile = “test.xlsx”; $objreader = phpexcel_iofactory::createreaderforfile($inputfile); $objreader->setreaddataonly(true); $objphpexcel = $objreader->load($inputfile);  […]  $objwriter = new phpexcel_writer_pdf($objphpexcel); $objwriter->setsheetindex(0); $objwriter->setprecalculateformulas(true); $objwriter->save("test.pdf"); 

the pdf writer library using dompdf.
problem code above return me error when try create pdf specific file working on.

fatal error: uncaught exception 'phpexcel_calculation_exception' message 'sheet!c5 -> formula error: wrong number of arguments countifs() function: 4 given, 2 expected' in d:\xampp\htdocs\doc\phpxls\classes\phpexcel\cell.php:300 stack trace: #0 d:\xampp\htdocs\doc\phpxls\classes\phpexcel\writer\html.php(1174): phpexcel_cell->getcalculatedvalue() #1 d:\xampp\htdocs\doc\phpxls\classes\phpexcel\writer\html.php(436): phpexcel_writer_html->_generaterow(object(phpexcel_worksheet), array, 4) #2 d:\xampp\htdocs\doc\phpxls\classes\phpexcel\writer\pdf\dompdf.php(109): phpexcel_writer_html->generatesheetdata() #3 [internal function]: phpexcel_writer_pdf_dompdf->save('testing.pdf') #4 d:\xampp\htdocs\doc\phpxls\classes\phpexcel\writer\pdf.php(87): call_user_func_array(array, array) #5 d:\xampp\htdocs\doc\interface\xls2pdf_2.php(59): phpexcel_writer_pdf->__call('save', array) #6 d:\xampp\htdocs\doc\interface\xls2pdf_2.php(59): phpexcel_writer_pdf->save('testing.pdf') #7 {main} thrown in d:\xampp\htdocs\doc\phpxls\classes\phpexcel\cell.php on line 300 

you can see it’s “countifs()” assumption setreaddataonly(true) give me values of cells , ignore formulas after reading documentation realize not true. there way values of cell without formula?

if set $objwriter->setprecalculateformulas(false);

it work without error returned pdf file show formulas instead of calculated values in cells (obviously)

is there way make work intended to? reading / writing values , ignoring formula?

my suspicion error has separator in formula in local format using (german) semicolon in us/standard format comma formula looks in original file

=zÄhlenwenns(migration_lsa!$ar$2:$ar$121;">=1/4/2014";migration_lsa!$ar$2:$ar$121;"<=30/4/2014") 

and in theory should in phpexcel

=countifs(migration_lsa!$ar$2:$ar$121,">=1/4/2014",migration_lsa!$ar$2:$ar$121,"<=30/4/2014") 

the problem isn't separator @ all, issue if inserting formula phpexcel directly

=zÄhlenwenns(migration_lsa!$ar$2:$ar$121;">=1/4/2014";migration_lsa!$ar$2:$ar$121;"<=30/4/2014") 

when need set locale, , use translate methods before inserting it. internally (in both phpexcel , ms excel) formulae represented in english/us format. ms excel gui hides automatic translation on insert/display.

at moment, countifs() formula in phpexcel works single range/criteria pair.

you can work round splitting multiple range/criteria pairs single range/criteria pairs , adding together, so:

=countifs(migration_lsa!$ar$2:$ar$121,">=1/4/2014") +     countifs(migration_lsa!$ar$2:$ar$121,"<=30/4/2014") 

setreaddataonly(true) tells phpexcel reader read cell content, not read styles, format masks, print settings, conditional styles, etc... formulae still cell content


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -