欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

生成Excle模板,SXSSFWorkbook-2007之后版本不上传服务器

发布时间:2025/6/15 编程问答 36 豆豆
生活随笔 收集整理的这篇文章主要介绍了 生成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

转载于:https://www.cnblogs.com/caixiaoyou/p/10192225.html

总结

以上是生活随笔为你收集整理的生成Excle模板,SXSSFWorkbook-2007之后版本不上传服务器的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。