Question

I'm trying to insert a "COUNTIFS" formula and I know it's not a supported function, but I have the calculation setting turned off on the writer. It's not throwing any errors. However,

$active_sheet->setCellValue('C3', "=COUNTIFS('INVENTORY'!$H:$H,1,'INVENTORY'!$C:$C,\"ADMIN\",'INVENTORY'!$N:$N,1)");

Is getting written to the file as

COUNTIFS('INVENTORY'!:,1,'INVENTORY'!:,"ADMIN",'INVENTORY'!:,1)

I read on another page somewhere that referencing columns like this wasn't supported either, but I also tried putting them in like "$C2:$C3000" and it didn't help.

Was it helpful?

Solution

The issue would be that you're using double quotes around your second parameter. PHP is trying to replace $H, $C and $N with actual variables.

Try using single quotes and escaping the existing single quotes within the string.

Here are the docs on how PHP parses double quoted strings which might help.

OTHER TIPS

So the solution was to remove or escape the dollar signs ($). I removed them and it worked fine, and then I escaped them and it also worked!!

Resulting example line:

$active_sheet->setCellValue('C3', "=COUNTIFS('INVENTORY'!\$H:\$H,1,'INVENTORY'!\$C:\$C,\"ADMIN\",'INVENTORY'!\$N:\$N,1)");

edit: wow, noob mistake. Credit goes to Ian Belcher.

Column and Row ranges aren't supported by PHPExcel at this point: you need to supply an actual range (e.g. 'INVENTORY'!$H1:$H500 rather than simply 'INVENTORY'!$H:$H.

There are also a couple of known issues when inserting or deleting new rows or columns into a worksheet when it doesn't correctly adjust an existing formula to reflect that change. Those issues have been fixed in the latest develop branch code on github, so you may want to try again using that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top