我正在使用 Apache POI 创建一个大型 Excel 电子表格,该电子表格对于客户端来说非常繁重,以后可能会使用新公式修改我的程序代码。我遇到的一个大问题是处理 POI 工作簿的行和列的索引为 0 的事实,而 Excel 公式处理文档时就好像它是索引的 1。我现在正在使用帮助类进行转换:
class RowHelper {
public static int getCell(int col) {
return col - 1;
}
public static String getCellAddress(int row, int col) {
return CellReference.convertNumToColString(col) + row;
}
}
当我在文档中编辑行时,我会这样写:
posRow.getCell(RowHelper.getCell(189)).setCellFormula(String.format("COUNT(%1$s:%2$s)", RowHelper.getCellAddress(2, 177), RowHelper.getCellAddress(ActiveSheet.getPhysicalNumberOfRows(), 177)));
//=COUNT(FU2:FU477)
但这不是很干净的代码,而且客户端以后使用起来也不是很容易。有没有更好的方法来做到这一点?