代码之家  ›  专栏  ›  技术社区  ›  Geek

POI未写入excel[重复]

  •  -1
  • Geek  · 技术社区  · 11 年前

    我使用POI来编写excel报告。这是我的代码:

            HSSFWorkbook wb = new HSSFWorkbook();
            HSSFSheet sheet = wb.createSheet("Export To Excel");     
    
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-Disposition", "attachment; filename=avt.xls");
    
            HSSFRow row = sheet.createRow(0);
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("AAAAAAAAAAAAAA");
            cell = row.createCell(1);
            cell.setCellValue("BBBBB");
    //        cell.setCellStyle(cellStyle);
    
    
    
    
            FileOutputStream out =  new FileOutputStream("avt.xls");    
            wb.write(out);     
            out.close();     System.out.println("Excel written successfully..");  
    

    当我点击按钮时,excel弹出窗口会打开并显示警告消息,但没有任何内容写入excel。我在编译器中也没有看到任何错误。怎么了>?

    1 回复  |  直到 8 年前
        1
  •  3
  •   Serkan Arıkuşu    11 年前

    FileOutputStream尝试写入服务器端的文件。 如果您试图用响应来编写它,那么您应该使用响应的输出流。

    wb.write(response.getOutputStream());
    response.getOutputStream().close();