How to get Cell Reference using Cell?

2019-05-07 12:43发布

问题:

I am using apache poi 3.11, from CellReference, I can get rowIndex and Column Index, using following code.

CellReference cr = new CellReference("A1");
row = mySheet.getRow(cr.getRow());
cell = row.getCell(cr.getCol());

But my rowIndex and columnIndex are generated dynamically, how can I get CellReference using rowIndex and columnIndex?

XSSFRow row = mySheet.getRow(rowIndex); 
XSSFCell cell = row.getCell(columnIndex);

回答1:

Create a CellReference instance using the CellReference(int pRow, int pCol) constructor of the CellReference class, and the formatAsString method of the created instance.



回答2:

You can get column in string by following static method and appending row number to result column String

ColString= CellReference.convertNumToColString(columnIdex)