1 pièce(s) jointe(s)
Fichier de sortie Excel généré par JExcelAPI
Bonjour,
J'essaye de sauvegarder les données d'une JTable dans un fichier excel grâce à JExcelAPI mais quand je veux ouvrir le fichier de sortie il m'affiche un message disons que le format du fichier n'est pas valide ou bien le fichier est corrompu.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| WritableWorkbook workbook = null;
try {
/* On créé un nouveau worbook et on l'ouvre en écriture */
String fileName = TmfDirTfd.getText();
workbook = Workbook.createWorkbook(new File("CSTraceAnalysis.xlsx"));
/* On créé une nouvelle feuille (test en position 0) et on l'ouvre en écriture */
WritableSheet sheet = workbook.createSheet("CSTraceAnalysis", 0);
/* Creation des titres */
for (int j=0; j<ResultTbl.getColumnCount() ;j++){
Label label = new Label(0, j, ResultTbl.getColumnName(j));
//label.setCellFormat((CellFormat) Color.BLACK);
sheet.addCell(label);
}
/* Creation des autres champs */
for (int i = 0 ; i<ResultTbl.getRowCount(); i++){
for (int j=0; j<ResultTbl.getColumnCount() ;j++){
if(ResultTbl.getValueAt(i, j) != null){
Label label = new Label(i, j, ResultTbl.getValueAt(i, j).toString());
//label.setCellFormat((CellFormat) Color.BLACK);
sheet.addCell(label);
}
}
}
/* On ecrit le classeur */
workbook.write();
}
catch (IOException e) {
}
catch (RowsExceededException e) {
}
catch (WriteException e) {
}
finally {
if(workbook!=null){
/* On ferme le worbook pour libérer la mémoire */
try {
workbook.close();
}
catch (WriteException | IOException e) {
}
}
}
[ATTACH=CONFIG]147331[/ATTACH] |
ci-dessous une capture du message
Pièce jointe 147331
NB : j'utilise Excel 2013 et j'ai essayé avec les deux format ".xls" et ".xlsx"
Merci d'avance