2
我使用Apache POI来创建一个大的Excel电子表格,这对客户端来说可能非常公式沉重,后来可能会用新公式修改我的程序代码。我正在处理的最大问题是处理POI工作簿针对其行和列是0索引的事实,而Excel公式处理文档就好像它是1索引的。我使用的是帮助类,使转换现在:Apache POI Excel行和列索引
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)
但是,这是不是很干净的代码并且对于客户在以后的使用中不会很容易。有没有更好的方法来做到这一点?
感谢您的建议!我最终为每种类型(JWorkbook,JSheet等)创建了新的类,就像你做的那样,并且实现了与原始相同的接口,所以我可以将它们作为相同的对象传递。 – taiidani 2010-02-22 01:37:01