zoukankan      html  css  js  c++  java
  • 生成Excle模板,SXSSFWorkbook-2007之后版本不上传服务器

    @GetMapping("/downTemplateExcel")
        public void downTemplateExcel(HttpServletResponse response) throws IOException {
            SXSSFWorkbook workbook = new SXSSFWorkbook();
            SXSSFSheet sheet = workbook.createSheet("sheet");
            /**
             * 具体导出名字再议
             *
             * !!!!!!
             */
            String fileName = "test" + ".xlsx";
            int rowNum = 1;
            String[] headers = { "合作商ID", "合作商名称", "类型", "官网"};
            SXSSFRow row = sheet.createRow(0);
            for(int i=0;i<headers.length;i++){
                SXSSFCell cell = row.createCell(i);
                XSSFRichTextString text = new XSSFRichTextString(headers[i]);
                cell.setCellValue(text);
            }
            SXSSFRow row1 = sheet.createRow(rowNum);
            row1.createCell(0).setCellValue("");
            row1.createCell(1).setCellValue("");
            row1.createCell(2).setCellValue("");
            row1.createCell(3).setCellValue("");
    
            response.setContentType("application/octet-stream");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
            response.setCharacterEncoding("utf-8");
            response.setContentType("application/x-download");
    
            response.flushBuffer();
            workbook.write(response.getOutputStream());
        }

    如题,返回的是个url直接前端href即可。

    基本参考的就是下面的例子,只不过把版本从2003升级到了2007excle,谢谢。

    https://www.w3xue.com/exp/article/201812/11233.html

  • 相关阅读:
    git 命令
    Spring Boot Web应用开发 CORS 跨域请求支持
    layui demo
    jQuery jqGrid 4.7
    jQurey zTree Demo 3.5
    jQurey zTree API 3.5
    jQurey Select2 4.0
    jQurey Validation 1.16
    Laytpl 1.2
    My97DatePicker 4.8
  • 原文地址:https://www.cnblogs.com/caixiaoyou/p/10192225.html
Copyright © 2011-2022 走看看