Bonjour mon probleme c'est que je veux remplir un fichier excel avec le resultat d'une requete sql mais ça marche pas voila mon code :
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
26
27 public void GenererExcel2003(String requete) throws ClassNotFoundException, SQLException, IOException{ ResultSet rs=getResult(requete); ResultSetMetaData rmd= rs.getMetaData(); FileOutputStream fileOut = new FileOutputStream("workbook.xls"); int k=1; HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Feuille 1"); HSSFRow row1 = sheet.createRow((short)0); for(int i=0 ;i<rmd.getColumnCount();i++){ HSSFCell cell = row1.createCell(i); cell.setCellValue(rmd.getColumnName(i)); } while(rs.next()){ HSSFRow row = sheet.createRow((short)k); for (int i=1 ;i<=rmd.getColumnCount();i++){ HSSFCell cell = row.createCell(i); cell.setCellValue(rs.getObject(i).toString()); } k++; } wb.write(fileOut); fileOut.close(); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 static ResultSet getResult(String requete)throws ClassNotFoundException,SQLException{ Statement st =Connexion.ouvrirCon().createStatement(); return st.executeQuery(requete); }
Partager