我正在尝试向 Excel 中的单元格添加注释。我正在使用 jxl 库来做到这一点:
cell = sheet.getWritableCell(1, 2); // cols, rows
WritableCellFeatures wcf = cell.getWritableCellFeatures();
wcf.setComment("comment2");
最后一行返回:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
。尽管进行了多次尝试,但我无法修复它。帮助将不胜感激。谢谢你。
--EDIT--
这是修改后的addNumber方法:
private static void addNumber(WritableSheet sheet, int column, int row,
double d) throws WriteException, RowsExceededException {
Number number;
number = new Number(column, row, d, timesStandard);
//sheet.addCell(number); // need to add the cell first
if (user wants to add a comment) {
WritableCellFeatures wcf = new WritableCellFeatures();
wcf.setComment("the comment");
number.setCellFeatures(wcf);
}
//sheet.addCell(number); // but may need to add the cell with comments as well
}