Bonjour
je veux exporter les données d'un jtable vers un fichier excel
voici mon code :
mais ca marche pas parce que setCellValue ne possède pas un paramètre de type Object. comment je peut résoudre ce problème? et est ce qu'il existe une autre méthode différente de celle pour exporter un jtable vers excel?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Bordereau"); int a = jTable1.getRowCount(); int b =jTable1.getColumnCount(); for(int i=0;i<a;i++) { HSSFRow row = sheet.createRow(i); for(int j=0;j<b;j++) { HSSFCell cell = row.createCell((short)j); cell.setCellValue(jTable1.getValueAt(i,j)); } } FileOutputStream fileOut; try { fileOut = new FileOutputStream("monfichier.xls"); wb.write(fileOut); fileOut.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
merci
![]()
Partager