0
私はjtableをエクスポートするためにGoogleからいくつかの助けを借りて次のコードを書きましたが、Excelにエクスポートできません。また、NULLポインタも取得しています。java netbeansでexcelするためにjtableをエクスポートする
cell.setCellValue(model.getValueAt(i, j).toString());
全体のコードは
try {
HSSFWorkbook fWorkbook = new HSSFWorkbook();
HSSFSheet fSheet;
fSheet = fWorkbook.createSheet("new Sheet");
HSSFFont sheetTitleFont = fWorkbook.createFont();
File file = new File("D:\\MOHIT\\bill report\\report.xls");
HSSFCellStyle cellStyle = fWorkbook.createCellStyle();
sheetTitleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//sheetTitleFont.setColor();
TableModel model = report_table.getModel();
TableColumnModel model1 = report_table.getTableHeader().getColumnModel();
HSSFRow fRow1 = fSheet.createRow((short) 0);
for (int i = 0; i < model1.getColumnCount(); i++){
HSSFCell cell = fRow1.createCell((short) i);
cell.setCellValue(model1.getColumn(i).getHeaderValue().toString());
}
for (int i = 1; i < model.getRowCount(); i++) {
HSSFRow fRow = fSheet.createRow((short) i);
for (int j = 1; j < model.getColumnCount(); j++) {
HSSFCell cell = fRow.createCell((short) j);
cell.setCellValue(model.getValueAt(i, j).toString());
cell.setCellStyle(cellStyle);
}
}
FileOutputStream fileOutputStream;
fileOutputStream = new FileOutputStream(file);
try (BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream)) {
fWorkbook.write(bos);
}
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
ある誰かが、なぜ私はそれを修正するためにどのようにnullポインタ例外を取得しています私に言うことができます。
ありがとう –