如何将 JTable header 保存在 Excel 中我有一个代码,仅保存值,但 header 不包括我使用 POI 3.14 这是我的代码
for (int i = 0; i < model.getRowCount(); i++) {
XSSFRow excelRow = excelSheet.createRow(i);
for (int j = 0; j < model.getColumnCount(); j++) {
XSSFCell excelCell = excelRow.createCell(j);
excelCell.setCellValue(model.getValueAt(i, j).toString());
}
}
最佳答案
我得到了我的解决方案,谢谢
` for (int i = 0; i < model.getRowCount()+1; i++) {
SSFRow excelRow = excelSheet.createRow(i);
for (int j = 0; j < model.getColumnCount(); j++) {
if(i == 0){
XSSFCell excelCell = excelRow.createCell(j);
excelCell.setCellValue(model.getColumnName(j));
}else{
XSSFCell excelCell = excelRow.createCell(j);
excelCell.setCellValue(model.getValueAt(i-1, j).toString());
}
}
}`
关于java - 如何使用 poi 将 jtable 保存到 Excel(包括标题)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60256343/