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
。多くの試みにもかかわらず、私はそれを修正することはできません。ヘルプは高く評価されます。ありがとうございました。
--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
}
'cell.getWritableCellFeatures()'リターンヌル:
私はこれを作りましたfeaはありません確かに'WritableCellFeatures wcf = new WritableCellFeatures();を使って試してください。 wcf.setComment( "コメント"); cell.setCellFeatures(wcf); –
ifステートメントで、 'cell.setCellFeatures(wcf);'を 'cell.setCellFeatures(wcf);'に置き換えることができます。 ; ' –
'WritableCell cell = sheet.getWritableCell(column、row);'を追加し、 'number'を' cell'に置き換えましたが、コメントはありません – Hurdler