[英]How to save jtable to excel including headers using poi?
How can I get the JTable header to save in excel i have a code that only the values are saved but header is not including im using POI 3.14 heres my code如何让 JTable 标头保存在 excel 我有一个代码,只保存了值,但标头不包括使用 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());
}
}
i got my solution thanks我得到了我的解决方案谢谢
` 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());
}
}
}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.