response.setContentType("application/vnd.ms-excel");
String fileName = "统计列表.xls";
response.setHeader("Content-Disposition", "attachment; filename="
+ java.net.URLEncoder.encode(fileName, "UTF-8"));
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet;
HSSFRow row;
HSSFCell cell;
HSSFCellStyle style = wb.createCellStyle();
HSSFCellStyle style2 = wb.createCellStyle();
HSSFCellStyle style3 = wb.createCellStyle();
HSSFFont font = wb.createFont();
HSSFFont font2 = wb.createFont();
// 目录栏样式
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// set cell border
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setWrapText(true);
// 标头样式
style2.setFillBackgroundColor(HSSFColor.GREEN.index);
// 设定此样式的的背景颜色填充
style2.setFillPattern(HSSFCellStyle.FINE_DOTS);
style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// set cell border
style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
// 主体内容样式
style3.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// set cell border
style3.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style3.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style3.setBorderTop(HSSFCellStyle.BORDER_THIN);
style3.setBorderRight(HSSFCellStyle.BORDER_THIN);
font.setColor(HSSFFont.COLOR_NORMAL);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font2.setColor(HSSFFont.COLOR_RED);
font2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font2.setFontHeightInPoints((short) 15);
style.setFont(font);
style2.setFont(font2);
sheet = wb.createSheet();
sheet.setColumnWidth((short)0,(short)3000);
sheet.setColumnWidth((short)1,(short)5000);
sheet.setColumnWidth((short)2,(short)34000);
sheet.setColumnWidth((short)3,(short)5000);
sheet.setColumnWidth((short)4,(short)3000);
wb.setSheetName(0, "汇总", HSSFCell.ENCODING_UTF_16);
sheet.setDefaultColumnWidth((short) 12);
// 第一行列表头
row = sheet.createRow(0);
cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("求助信息列表");
sheet.addMergedRegion(new Region(0, (short) 0, 0, (short) 11));
cell.setCellStyle(style2);
row = sheet.createRow(1);
cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("序号");
cell.setCellStyle(style);
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("电话");
cell.setCellStyle(style);
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("内容");
cell.setCellStyle(style);
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("发布时间");
cell.setCellStyle(style);
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("状态");
cell.setCellStyle(style);
cell = row.createCell((short) 5);
Mo mm = null;
int i = 0;
for ( ; i < moList.size(); i++) {
mm=(Mo) moList.get(i);
row = sheet.createRow(i + 2);
cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(mm.getId());//会员号
cell.setCellStyle(style3);
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(mm.getMobile()); //手机号
cell.setCellStyle(style3);
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(mm.getMessage());
cell.setCellStyle(style3);
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(mm.getCreatetime()); //性别
cell.setCellStyle(style3);
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
if(("1").equals(mm.getStatus())){
cell.setCellValue("新发布");
}
else if(("1").equals(mm.getStatus())){
cell.setCellValue("待处理");
}
else if(("2").equals(mm.getStatus())){
cell.setCellValue("已核实");
}
else if(("3").equals(mm.getStatus())){
cell.setCellValue("无法核实");
}
else if(("4").equals(mm.getStatus())){
cell.setCellValue("删除");
}
else if(("5").equals(mm.getStatus())){
cell.setCellValue("已解决");
}
else if(mm.getStatus()==null){
cell.setCellValue("新发布");
}
cell.setCellStyle(style3);
cell = row.createCell((short) 5);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
}
OutputStream out = response.getOutputStream();
wb.write(out);
out.close();
log.info("SimpleJobStaticAction ends");
}
catch(Exception e)
{
log.info("CommodityAction出错");
e.printStackTrace();
}
return null;
1.注
页面编码:
<meta http-equiv="Content-Type" content="application/vnd.ms-excel; charset=utf-8" />
分享到:
相关推荐
struts2+poi实现excel表格导出
自己做的一个完整导出功能,struts2+poi导出excel 经过自己严格测试通过的。
利用纯struts2.0+poi插件 实现导出excel
1.本动态导入导出Excel工程导入Eclipse即可用行,支持所有版本的Excel导入导出。...2.程序使用Struts2+POI+SQLSever(SSH即Struts2+Hibernate+Spring)实现Excel动态数据导入和导出,压缩包内含程序源码文件。
struts2+poi实现excel文件的导出,虽然有很多jxl库实现的方案,而本方案是使用struts2 mvc, apache poi库实现excel的导入导出,文档很详细
struts2中利用poi导出excel的简单例子
Web开发技术,excel导出的详解,对POI导出EXCEL代码实现的详细解释
struts2+poi 实现Excel导出,带jar包,适合初学者
正在使用的java web项目中的SSH框架包,这些包没有冲突,是基于spring3+struts2.2+hibernate3的,还有jdbc驱动、mysql连接驱动jdbc包、mail包、dwr包、upload.jar包等。
程序使用Struts2(SSH即Struts2+Hibernate+Spring)+POI+MySQL实现Excel动态数据导入和导出,程序源码文件附带运行说明
SpringMVC+Hibernate+POI导入导出excel,参考了一些别人的代码自己做了修改。
程序使用Struts2(SSH即Struts2+Hibernate+Spring)+POI+MySQL实现Excel动态数据导入和导出,程序源码文件附带运行说明
由于一个项目要用到POI以及分页的技术,而我没有开发经验,花了一个星期的时间找了大量的资料,终于完成了poi的使用以及分页技术,发出来大家一起共享,所采用的框架是struts2.x+spring+hibrnate,可以自己导入包之后进行...
Struts2 poi 实现从数据库中导出excel表
基于springmvc+hibernate框架实现对mysql数据库的简单操作,并通过java+poi技术实现导出excel
项目内有个excel 拿出来 在index页面点击选择导入直接运行
程序使用Struts2(SSH即Struts2+Hibernate+Spring)+POI+MySQL实现Excel动态数据导入和导出,程序源码文件附带运行说明
包含SQLServer的数据库文件,直接...Struts2与Spring的整合,使用Apache的POI框架导出Excel等功能会让你愉悦一下的。看不惯有些人很烂的代码收上八九分的,两分是为了自己挣点分下资源,下过觉得不亏的给好评哦,亲~
包含整合后的sshjar包 外还有 json 连接池 poi等工具jar包