生成Excle模板,SXSSFWorkbook-2007之后版本不上传服务器
生活随笔
收集整理的這篇文章主要介紹了
生成Excle模板,SXSSFWorkbook-2007之后版本不上传服务器
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
@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", "合作商名稱", "類型", "官網(wǎng)"};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
轉(zhuǎn)載于:https://www.cnblogs.com/caixiaoyou/p/10192225.html
總結(jié)
以上是生活随笔為你收集整理的生成Excle模板,SXSSFWorkbook-2007之后版本不上传服务器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 办公文档加密,企业文档加密,强制性透明加
- 下一篇: 《游戏力》读书笔记作文4700字