struts2导出excel
来源:互联网 发布:卡巴斯基官网软件 编辑:程序博客网 时间:2024/05/18 00:44
使用jar包 jxl.jar
import jxl.Workbook;import jxl.write.Label;
@ActionDef(type = ActionType.PRIVATE)@Action(value = "compareExport", results = { @Result(name = "success", type = "stream") }) public String compareExport() throws Exception { String header="始发地,始发中转班次,目的地,产品类型,出入港,路由属性,流向货量,路由环节1,路由环节2,路由环节3,路由环节4,路由环节5,路由环节6,路由环节7,路由环节8,路由环节9,路由环节10,路由环节11"; String column="start_place,start_transfer_batch,dest,product_type,out_or_in,route_attr,volume,detail1,detail2,detail3,detail4,detail5,detail6,detail7,detail8,detail9,detail10,detail11"; List<Map<String,Object>> list = evaluatedao.findCompareList(areaType, createTm, null, null,null).getList(); export(header,column,list,"路由对比"); return null; }
public void export(String header,String column,List<Map<String,Object>> list,String excelName) throws Exception{ HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("UTF-8"); response.setContentType("application/vnd.ms-excel"); excelName=excelName+ new SimpleDateFormat("MMddHHmm").format(new Date())+".xls"; response.setHeader("Content-Disposition", "attachment; filename=" + new String(excelName.getBytes("GB2312"), "iso8859-1")); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "No-cache"); response.setDateHeader("Expires", 0); // 这个地方一定要进行编码的转换要不然中文字符会出现乱码. // 设置下载头信息.end, OutputStream output = null; InputStream fis = null; try { output = response.getOutputStream(); jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(output); jxl.write.WritableSheet ws = wwb.createSheet("用户通讯录", 0); String[] headerArr=header.split(","); String[] columnArr=column.split(","); for (int i=0;i<headerArr.length;i++) { //设置表头 ws.addCell(new Label(i, 0, headerArr[i])); // 设置显示长度. ws.setColumnView(i, 20); } for (int i = 0; i < list.size();i++) { Map<String,Object> obj = (Map<String,Object>) list.get(i); for(int j=0;j<columnArr.length;j++){ Object val=obj.get(columnArr[j]); if (null==val || "null".equals(val.toString())) { val="";} ws.addCell(new Label(j, i + 1, val.toString() )); } } wwb.write(); wwb.close(); } catch (Exception e) { System.out.println("Error!"); e.printStackTrace(); } finally {// 正常关闭输入输出流. try { if (fis != null) { fis.close(); fis = null; } } catch (Exception e) { e.printStackTrace(); } try { if (output != null) { output.close(); output = null; } } catch (Exception e) { e.printStackTrace(); } } }
1 0
- struts2 导出excel
- struts2导出excel文件
- Struts2导出Excel
- struts2 导出excel
- struts2 导出excel
- Struts2导出Excel
- struts2导出excel笔记
- Struts2 poi导出excel
- Struts2 导出excel完整版
- struts2 导出excel
- struts2导出excel笔记
- struts2导出excel
- struts2导出excel java 导出excel
- struts2导出excel java 导出excel
- struts2 用jxl 导出excel
- struts2导出数据到Excel
- java/Struts2 jqgrid 导出excel
- struts2 使用注解 导出excel
- ThreadPool用法与优势
- Ubuntu Thunderbird Exchange Server
- ajax学习心得
- fmt:formatDate标签的输出格式
- Linux CPU affinity
- struts2导出excel
- iOS 视图控制器转场详解(下)
- 高性能后台服务器架构设计
- 动态规划算法 决策树(ID3 C4.5)
- AlphaGo背后的搜索算法:蒙特卡罗树搜索 && alphago 代码
- scala函数
- request.getParameter()与request.setAttribute()的区别
- 切换了服务器中间件后,JNDI出现错误
- php排序法--冒泡排序,选择排序,插入排序