java中poi如何得到excel 单元格地址?

来源:百度知道 编辑:UC知道 时间:2024/05/13 23:40:30
例如得到A1,A2,B1,B2.....等这些地址?谢谢!
是地址,不是值!!!

        // 大概这么个思路,没验证~
public static String getlocationFromCell(Cell cell) {
int colIndex = cell.getColumnIndex();
// note: 行的序列号开始于1 
int rowIndex = cell.getRowIndex()+1;
String colStr = null;
if(colIndex<26) {
colStr = (char)(colIndex+65)+"";
} else {
char a = (char)(colIndex/26+64);
char b = (char)(colIndex%26+65);
colStr = a+""+b;
}
return colStr+rowIndex;
}

如果你使用的是POI那么就是下面的方法
//根据传过来的文件名创建workbook
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));
//获得excel文件的sheet数量
int sn = wb.getNumberOfSheets();
//依次处理sheet表单
for (int i = 0; i < sn; i++) {
HSSFSheet sheet = wb.getSheetAt(i);
//获得第i张表单的所有行数
f