//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();
}
}
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();
}
}