我正在尝试向Excel中的单元格添加注释。我使用JXL库来做到这一点:使用jxl库向使用Java的Excel文件中的单元格添加注释
cell = sheet.getWritableCell(1, 2); // cols, rows
WritableCellFeatures wcf = cell.getWritableCellFeatures();
wcf.setComment("comment2");
最后一行返回:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
。尽管许多尝试,我无法修复它。帮助将不胜感激。谢谢。
- 编辑 -
这是修改后的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
}
'cell.getWritableCellFeatures()'返回null,因为电池没有fea真实存在。尝试使用'WritableCellFeatures wcf = new WritableCellFeatures(); wcf.setComment( “意见”); cell.setCellFeatures(wcf);' – 2012-04-14 19:49:20
在if语句中可以添加'Cell cell = sheet.getWritableCell(column,row);',然后用'cell.setCellFeatures(wcf)替换'number.setCellFeatures(wcf);' ;' – 2012-04-14 21:11:53
我增加了'WritableCell cell = sheet.getWritableCell(column,row);'并用'cell'替换了'number',但注释不存在 – Hurdler 2012-04-14 21:20:00