Jerry
Jerry

Reputation: 341

How to get current Cell position of an Excel sheet using Apache POI

Is there any way to calculate or is there any built-in API to get the current Cell position of an Excel sheet using Apache Poi??

Like A10 or F61 or AG34 or BK567 etc.

Note: I'm using poi3.9.jar. Thanks in advance. It would be preferable if there's a built-in api.

I need this cell position because, I want to use the below Formula to set value.

Formula is : cell.setCellFormula("G16/F16*100");

Upvotes: 0

Views: 1058

Answers (1)

Gagravarr
Gagravarr

Reputation: 48326

If you have the Apache POI Cell object to hand, you can call cell.getAddress() to get a CellAddress object.

From that, you can cell formatAsString to get the cell's address eg A1

int colNum = 2; // eg
Cell cell = row.getCell(colNum);
CellAddress addr = cell.getAddress();
String asExcel = addr.formatAsString(); // eg C3

Upvotes: 1

Related Questions