How to convert Excel to XML using java?

前端 未结 5 1796
抹茶落季
抹茶落季 2020-12-04 03:45

i want to convert my input Excel file into the Output XML file.

If anybody has any solution in java for how to take input Excel file and how to write to XML as outpu

5条回答
  •  被撕碎了的回忆
    2020-12-04 04:35

    File excelFile = new File(excelFilename);
    
    // Create model for excel file
    if (excelFile.exists()) {
        try {
            Workbook workbook = Workbook.getWorkbook(excelFile);
            Sheet sheet = workbook.getSheets()[0];
    
            TableModel model = new DefaultTableModel(sheet.getRows(), sheet.getColumns());
            for (int row = 0; row < sheet.getRows(); row++) {
                for (int column = 0; column < sheet.getColumns(); column++) {
                    String content = sheet.getCell(column, row).getContents();
                    model.setValueAt(content, row, column);
                }
            }
    
            previewTable.setModel(model);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error: " + e);
        }
    
    } else {
        JOptionPane.showMessageDialog(null, "File does not exist");
    }
    

提交回复
热议问题