How to get Cell Reference using Cell?

半腔热情 提交于 2019-12-07 10:29:29

问题


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)


来源:https://stackoverflow.com/questions/33095423/how-to-get-cell-reference-using-cell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!