I needed to write data to an excel file, which I was able to do. Another criterion is that if the status cell for the same row is "Received," the piece cell must be included in the summing.
Additionally, only visible cells should be included in the summing. I currently have two columns named "Status" (Column A2:A10) and "piece" (Column B2:B10), and I've added the following formula using the Apache-poi library:
SUMPRODUCT(SUBTOTAL(9,OFFSET(B2:B10,ROW(B2:B10)-(ROW(B2)),0,1)),(--(A2:A10="Recived")))
When the Java code is executed, the file is correctly written, but when I access the file, the formula cell displays as #VALUE! The value for the formula appears when I select the formula bar and press Enter.
Every time I open the Excel file, I want the formula's value to be visible.
Below is Java code
cell.setCellType(Cell.CELL_TYPE_FORMULA);
cell.setCellFormula("SUMPRODUCT(SUBTOTAL(9,OFFSET(B2:B10,ROW(B2:B10)-(ROW(B2)),0,1)),(--(A2:A10=\"Recived\")))");