excel文件的下载
Posted 沙漠里的小鱼
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了excel文件的下载相关的知识,希望对你有一定的参考价值。
@Override protected void buildExcelDocument(Map<String, Object> map, HSSFWorkbook hssfWorkbook, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { List<TGcxxInvitationCode> list = (List<TGcxxInvitationCode>) map.get("map"); HSSFSheet sheet = hssfWorkbook.createSheet(); //创建表头 HSSFRow row = sheet.createRow(0); HSSFCell cell = null; String[] headers = new String[]{"姓名","手机","账号","邀请时间","注册时间"}; for(int i=0;i<headers.length;i++) { cell = row.createCell(i); cell.setCellValue(headers[i]); } //创建表内容 if(list != null & list.size()>0) { for(int m=0;m<list.size();m++) { HSSFRow bodyRow = sheet.createRow(m + 1); TGcxxInvitationCode invitation = list.get(m); cell = bodyRow.createCell(0); cell.setCellValue(invitation.getUserTruename()); cell = bodyRow.createCell(1); cell.setCellValue(invitation.getUserPhone()); cell = bodyRow.createCell(2); cell.setCellValue(invitation.getLoginName()); cell = bodyRow.createCell(3); cell.setCellValue(Util.formatDate(invitation.getCreateTime())); cell = bodyRow.createCell(4); cell.setCellValue(Util.formatDate(invitation.getCreateDate())); } } String filename = "被邀请人详情信息"; httpServletResponse.setContentType("application/vnd.ms-excel"); httpServletResponse.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(filename,"UTF-8") +".xls"); OutputStream outputStream = httpServletResponse.getOutputStream(); hssfWorkbook.write(outputStream); outputStream.flush(); outputStream.close(); }
以上是关于excel文件的下载的主要内容,如果未能解决你的问题,请参考以下文章
Excel 模板下载功能 + 前后端解析 Excel 文件代码封装 + 前端上传 Excel 至数据库(SpringBoot + Vue 版)
Excel 模板下载功能 + 前后端解析 Excel 文件代码封装 + 前端上传 Excel 至数据库(SpringBoot + Vue 版)
Excel 模板下载功能 + 前后端解析 Excel 文件代码封装 + 前端上传 Excel 至数据库(SpringBoot + Vue 版)