
Hello Java Developers,
Here’s a straight question. How would I be able to set the Cell’s formula within a loop in Apache POI?
Here’s an information to support my question:
Illustration 1: Cell C1 has the formula of SUM(C6:C7) which can be done by simply hard coding the formula myCell.setCellFormula("SUM(C6:C7)").
On the other hand:
Illustration 2: This is my desired output. I want to set a formula on Cells C1, D1, and E1 for example. How can this be done within a loop?
Why would I want it within a loop?
– Hard-coding would be tiresome. 3 cells are just and example. Currently I have hundreds of cells waiting for their formula.
– Row count are not specified, it will be based on the number of rows created by the program.
What I have done?
– Googled.
– Searched for similar question.
– Apache POI’s column is represented by an Integer (Number of cells within a row).
The formula requires Alpha C2 (Column C, Row 2). I tried to loop through the Spreadsheet and realized that if I continue, the formula will result to SUM(26:27) (Where: 2 = Column C, and Row 6(Base 1: rowCount + 1) which I want to be SUM(C6:C7)
I have finally solved the problem.
CellReference.convertNumToColString(myColumnNumber)will return the column name