0,0 ⇒ A1
输出:
A1
AC4
IV6
需要区域转换成
输出:
A1:D5
其中用了POI的库,下载。
[url]http://poi.apache.org/download.html[/url]
如果希望反过来。
A1 ⇒ 0,0
区域的
输出:
0:4:0:3
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
public class TestPOI {
public static void main(String[] args) {
System.out.println(getCellName(0, 0)); //A1
System.out.println(getCellName(3, 28)); //AC4
System.out.println(getCellName(5, 255)); //IV6
}
public static String getCellName(int row, int col) {
if (row < 0) {
throw new IllegalArgumentException("row: " + row);
}
if (col < 0) {
throw new IllegalArgumentException("col: " + col);
}
//return CellReference.convertNumToColString(col) + (row + 1);
return new CellReference(row, col).formatAsString();
}
}
输出:
A1
AC4
IV6
需要区域转换成
CellRangeAddress address = new CellRangeAddress(0, 4, 0, 3);
System.out.println(address.formatAsString());
输出:
A1:D5
其中用了POI的库,下载。
[url]http://poi.apache.org/download.html[/url]
如果希望反过来。
A1 ⇒ 0,0
CellReference cr = new CellReference("A1");
System.out.println(cr.getRow() + ":" + cr.getCol());
区域的
CellRangeAddress address = CellRangeAddress.valueOf("A1:D5");
int firstRow = address.getFirstRow();
int lastRow = address.getLastRow();
int firstColumn = address.getFirstColumn();
int lastColumn = address.getLastColumn();
System.out.println(firstRow + ":" + lastRow + ":" + firstColumn + ":" + lastColumn);
输出:
0:4:0:3