• 【POI】导出excel文件,不生成中间文件,直接将内存中的数据创建对象下载到浏览器


     不是从InputStream中read,然后outputStream再write

    @RequestMapping("download4Excel")
        public void download4Excel(HttpServletResponse response){
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet sheet = workbook.createSheet("测试Sheet");
            
            sheet.setColumnWidth(1, 7000);
            Row row = sheet.createRow(0);
            Cell cell = row.createCell(1);
            cell.setCellValue("德玛西亚");
            
            
            try {
                
                response.setContentType("multipart/form-data");
                response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode("测试生成Excel文件.xlsx", "utf-8"));
                OutputStream outputStream = response.getOutputStream();
                workbook.write(outputStream);
                outputStream.close();
                workbook.close();
                
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
            
        }
    View Code

  • 相关阅读:
    django email用法
    django ImageField用法
    django集成微博内容
    python读写zip文件
    读写文件
    404渲染
    bzoj1297 / P4159 [SCOI2009]迷路
    bzoj1009 / P3193 [HNOI2008]GT考试
    poj2115 C Looooops(exgcd)
    bzoj1407 / P2421 [NOI2002]荒岛野人(exgcd)
  • 原文地址:https://www.cnblogs.com/sxdcgaq8080/p/7571819.html
Copyright © 2020-2023  润新知