简体   繁体   English

如何使用 poi 将 jtable 保存到 excel 包括标题?

[英]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.

相关问题 如何使用Apache POI为Excel标头单元格着色? - How to color Excel Headers cells using Apache POI? 将 JTable 数据(包括表头)导出到 Excel 文件 - Exporting JTable Data including Table Headers to Excel File 从jtable导出到excel时如何合并列? 使用apache POI - how to merge columns while exporting from jtable to excel? using apache POI 如何获得类似Excel的JTable标头 - how to obtain excel-like JTable headers 如何使用apache poi将2016年的excel复制到另一个(包括公式,单元格样式和日期格式)。 - How to copy a 2016 excel to another(including formulas, cell style and date format) using apache poi. 如何使用 Apache Poi 中的公式保存 excel? - How to save excel with formula in Apache Poi? 如何从 JTable 保存到 CSV 或 Excel - How to save from JTable to CSV or Excel 如何在Apache POI中检查Excel列标题是否按特定顺序 - How to check if excel column headers are in certain order in apache poi 如何使用apache POI将excel文件数据保存为mysql数据库表作为记录记录 - How to save the excel file data into mysql database table as a record by record using apache POI 如何使用 Java 和 Apache POI 在 Excel 中禁用“保存时从文件属性中删除个人信息” - How to disable "Remove Personal Information from file properties on save" in Excel using Java and Apache POI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM