欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

poi导出到本地 抉择本地路径 保存到本地

更新时间: 2014-01-05 00:51:03 责任编辑: Author_N1

 

poi导出到本地 选择本地路径 保存到本地
//poi导出excel 保存到本地

public void exportExcel(HttpServletRequest req, HttpServletResponse resp) throws IOException{

HSSFWorkbook wb = new HSSFWorkbook();
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
resp.setContentType("application/x-download");

String filedisplay = "未匹配的产品清单.xls";
filedisplay = URLEncoder.encode(filedisplay, "UTF-8");
resp.addHeader("Content-Disposition", "attachment;filename="+ filedisplay);
HSSFSheet sheet = wb.createSheet("未匹配产品");
sheet.setColumnWidth(0, 50*160);
HSSFFont font = wb.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 16);

HSSFRow row = sheet.createRow((int) 0);

HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);

HSSFCell cell = row.createCell(0);
cell.setCellValue("产品名称");

Map<String, Object> params = new HashMap<String, Object>();
params.put("userId", this.getMember().getId());
params.put("matchabled", 0);
List<Match> matchs = this.getBeanManager().listBean(Match.class, params);

for (int i = 0; i < matchs.size(); i++) {
row = sheet.createRow((int) i + 1);
Match match = (Match) matchs.get(i);
row.createCell(0).setCellValue(match.getName());
}
try {
OutputStream out = resp.getOutputStream();
wb.write(out);
out.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 00:51:03
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/560/
本文WWW.DOC100.NET DOC100.NET版权所有。