将jtable导出到xml无效,仅将标题打印在xml中

时间:2019-03-20 22:19:53

标签: excel jtable

我一直在努力从excel表格的jtable中获取内容.view是我的jframe,其中包含jtable。在执行操作时.jtable的标题仅打印而不显示其内容。

public class exporter {
View e=new View();

 public void exortTable(JTable table) throws IOException{
     TableModel model=e.jtable.getModel();
                 try {

        WritableWorkbook workbook1 = Workbook.createWorkbook(new File("C:\\stu\\hh.xls"));
        WritableSheet sheet1 = workbook1.createSheet("First Sheet", 0);


        for (int i = 0; i < model.getColumnCount(); i++) {
            jxl.write.Label column = new jxl.write.Label(i, 0, model.getColumnName(i));
            sheet1.addCell(column);
        }
        int j = 0;
        for (int i = 0; i < model.getRowCount(); i++) {
            for (j = 0; j < model.getColumnCount(); j++) {
           jxl.write.Label  row = new jxl.write.Label (j, i + 1,
                        model.getValueAt(i, j).toString());
                sheet1.addCell(row);
            }
        }
        workbook1.write();
        workbook1.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

 }

0 个答案:

没有答案