博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring之xls文件下载
阅读量:4112 次
发布时间:2019-05-25

本文共 932 字,大约阅读时间需要 3 分钟。

需求:

基于poi的xls文件下载

实现:

控制层:

@RequestMapping(value = "/exportxls", method = RequestMethod.GET)public void exportxls(HttpServletRequest request, QueryItem queryItem,		HttpServletResponse response) throws Exception {	 	HSSFWorkbook workbook = new HSSFWorkbook();	// 创建工作表对象并命名	Sheet sheet = workbook.createSheet();	/* header start */	Row rowHeader = sheet.createRow(0);	Cell cell1 = rowHeader.createCell(0, Cell.CELL_TYPE_STRING);	cell1.setCellValue("ID");	Cell cell2 = rowHeader.createCell(1, Cell.CELL_TYPE_STRING);	cell2.setCellValue("姓名");	Cell cell3 = rowHeader.createCell(2, Cell.CELL_TYPE_STRING); 	 	response.reset();	// 设置response的Header	response.addHeader("Content-Disposition", "attachment;filename="			+ CommonUtils.getUUID() + ".xls");	OutputStream out = new BufferedOutputStream(response.getOutputStream());	response.setContentType("application/octet-stream");	workbook.write(out);	out.flush();	IOUtils.closeQuietly(out);}

 

转载地址:http://hlqsi.baihongyu.com/

你可能感兴趣的文章
UVA 10256 凸包问题-点集划分
查看>>
LA 4728 旋转卡壳模板
查看>>
LA 2797 Monster Trap 怪物逃脱 平面区域
查看>>
UVA 10047 骑单车
查看>>
UVA 11275 判断空间三角形是否相交
查看>>
Find a way bfs搜索 容易出错
查看>>
C - Charm Bracelet dp
查看>>
CF 551B 暴力+字符串
查看>>
CF 551c 二分搜索+思维题
查看>>
UVA 10054
查看>>
cf 550A 字符串统计
查看>>
CF 字符串+数论
查看>>
POJ 1274 The Perfect Stall 二分匹配模板
查看>>
CF Mike and Fax 字符串组成
查看>>
POJ 3250 单调栈模板
查看>>
CF #338B Longtail Hedgehog 画刺猬
查看>>
Good Bye 2015 B. 位运算
查看>>
Cf #179 (Div. 1) B. Greg and Graph 活用三重floyd
查看>>
CF #165 DIV2 E 最大流的流向
查看>>
Manthan 2011 A. Partial Teacher 拓扑排序or直接数组处理
查看>>