Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement excel's array formula feature using Apache POI

I have a formula in excel sheet that has the following format

{=SUM(IF(C3:C65536=F11,B3:B65536))}

its a formula array. How do I implement this in Java using Apache POI API?

I did this in java

cell.setCellType(XSSFCell.CELL_TYPE_FORMULA);
cell.setCellFormula("SUM(IF(C3:C65536=F"+totalCtr+",B3:B65536))");

where totalCtr is an int variable that iterates from 0... n
and is part of "F" in the formula. So I can go from one cell to the next.

like image 940
dimas Avatar asked May 06 '26 15:05

dimas


1 Answers

The newer Version of POI supports array formulas

see https://poi.apache.org/spreadsheet/formula.html

 Array Formulas: via Sheet.setArrayFormula() and Sheet.removeArrayFormula()
like image 58
outofBounds Avatar answered May 08 '26 06:05

outofBounds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!