Bonjour j'ai reussit a généré mon fichier excel avec api poi mais quand le navigateur demande où l'enregister je trouve que le fichier est vide
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
28
29
30
31
32
33
34
35
36
 
 HttpSession session = request.getSession();
        String requete=(String) session.getAttribute("requete");
 
        String nom=(String) request.getParameter("nom_f");
         response.setContentType ("application/vnd.ms-excel" );
         response.setHeader ("Content-disposition", "attachement; filename="+nom+".xls" );
        ResultSet rs=getResult(requete);
           ResultSetMetaData rmd= rs.getMetaData();
 
            int k=1;
          HSSFWorkbook wb = new HSSFWorkbook();
          HSSFSheet sheet = wb.createSheet("Feuille");
          HSSFRow row1 = sheet.createRow((short)0);
            HSSFCellStyle style = wb.createCellStyle();
            HSSFFont font = wb.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            style.setFont(font);
 
           for(int i=0 ;i<rmd.getColumnCount();i++){
               HSSFCell cell = row1.createCell((short) i);
               cell.setCellValue(new HSSFRichTextString(rmd.getColumnName(i+1).toString()));
               cell.setCellStyle(style);
               //System.out.println(rmd.getColumnName(i+1));
           }
            while(rs.next()){
               HSSFRow row = sheet.createRow((short)k);
          for (int i=0 ;i<rmd.getColumnCount();i++){
                HSSFCell cell = row.createCell((short) i);
                cell.setCellValue(new HSSFRichTextString(rs.getObject(i+1).toString()));
          }
               k++;
               }
             FileOutputStream fileOut = new FileOutputStream(nom+".xls");
            wb.write(fileOut);
            fileOut.close();