- 浏览: 668035 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
qinshubao152:
参考:http://www.see-source.com/bl ...
关于android USB Host 串口编程 -
q328965539:
哥们 我做的数据也都是错误的啊····我怎么可以知道自己otg ...
关于android USB Host 串口编程 -
hgkmail:
好文
android中跨进程通讯的4种方式 -
cczscq:
楼主,我这里有个问题!我这里有个自己制作的font.ttf,这 ...
android字体的工作原理 -
blueice1986:
既然springMVC比struts好那么多的话那struts ...
为什么有了Struts 还要Spring MVC
上一篇,我写了jxl的理论的东西比较多, 是为了让我自己学习,更好让我去完成项目中的一個模块, 就是在ext的gridpanel显示出的数据显示出來, 因为导出的数据是两个gridpanel的数据所以这就算比较复杂的导出了, 单单使用ext自带的excel导出,就难以做到啦。
简单的说明之后, 我还是把代码贴吧。一整个controller方法
效果图:
简单的说明之后, 我还是把代码贴吧。一整个controller方法
@SuppressWarnings("unchecked") @RequestMapping("/pages/deliveryPoint/deliveryPointSearch/exportExcel.page") public String exportExcel(HttpServletRequest request, HttpServletResponse response){ Map condition = new HashMap(); String regieOrgCode = request.getParameter("regieOrgCode_export"); String regieDeptCode = request.getParameter("regieDeptCode_export"); condition.put("custName", request.getParameter("custName_export")); condition.put("regieOrgCode", regieOrgCode); condition.put("regieDeptCode", regieDeptCode); condition.put("grantDate1", request.getParameter("grantDate1_export")); condition.put("grantDate2", request.getParameter("grantDate2_export")); String regieOrgName = " 烟草专卖局"; if(StringUtils.isNotBlank(regieOrgCode)){ RmRegieOrg obj = rmRegieOrgService.getRmRegieOrg(regieOrgCode); regieOrgName = obj.getRegieOrgName(); } String regieDeptName = " 专管所"; if(StringUtils.isNotBlank(regieDeptCode)){ RmRegieDept obj = rmRegieDeptService.getRmRegieDept(regieDeptCode); regieDeptName = obj.getRegieDeptName(); } SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); List<Map> custMap = rmDeliveryPointApplyDetailService.findCustMapForExport(condition); response.setHeader("Content-disposition", "attachment;filename=text.xls"); response.setContentType("application/msexcel"); try { OutputStream os = response.getOutputStream(); jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os); jxl.write.WritableSheet ws = wwb.createSheet("定点取货点寄货户实时更新汇总表", 0); WritableFont titleFont = new WritableFont(WritableFont.createFont("宋体"), 15,WritableFont.BOLD); WritableCellFormat titleFormat = new WritableCellFormat(titleFont); titleFormat.setAlignment(jxl.format.Alignment.CENTRE); titleFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); titleFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.NONE); WritableFont titleFont1 = new WritableFont(WritableFont.createFont("宋体"), 11,WritableFont.NO_BOLD); WritableCellFormat titltFormat1 = new WritableCellFormat(titleFont1); titltFormat1.setAlignment(jxl.format.Alignment.LEFT); titltFormat1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); titltFormat1.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.NONE); WritableFont cellFont = new WritableFont(WritableFont.createFont("宋体"), 9,WritableFont.NO_BOLD); WritableCellFormat cellFormat = new WritableCellFormat(cellFont); cellFormat.setAlignment(jxl.format.Alignment.CENTRE); cellFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); cellFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); cellFormat.setWrap(true); WritableFont headFont = new WritableFont(WritableFont.createFont("宋体"), 9,WritableFont.BOLD); WritableCellFormat headFormat = new WritableCellFormat(headFont); headFormat.setAlignment(jxl.format.Alignment.CENTRE); headFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); headFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); headFormat.setWrap(true); int rowIndex = 0 ; //Excel 行索引 jxl.write.Label labelC = new jxl.write.Label(0, 0, "定点取货点寄货户实时更新汇总表",titleFormat); ws.addCell(labelC); ws.mergeCells(0, rowIndex, 8, rowIndex); ws.setRowView(rowIndex, 800); rowIndex = rowIndex + 1; // 下一行 labelC = new jxl.write.Label(0, rowIndex, regieOrgName+" "+regieDeptName, titltFormat1); ws.addCell(labelC); ws.mergeCells(0, rowIndex, 8, rowIndex); ws.setRowView(rowIndex, 600); for(int i=0;i<custMap.size();i++){ rowIndex = rowIndex + 1; // 下一行 labelC = new jxl.write.Label(0, rowIndex, "取货点姓名", headFormat); ws.addCell(labelC); labelC = new jxl.write.Label(1, rowIndex, "许可证号码", headFormat); ws.addCell(labelC); labelC = new jxl.write.Label(2, rowIndex, "经营地址", headFormat); ws.addCell(labelC); labelC = new jxl.write.Label(3, rowIndex, "序号", headFormat); ws.addCell(labelC); labelC = new jxl.write.Label(4, rowIndex, "寄货户姓名", headFormat); ws.addCell(labelC); labelC = new jxl.write.Label(5, rowIndex, "许可证号码", headFormat); ws.addCell(labelC); labelC = new jxl.write.Label(6, rowIndex, "经营地址", headFormat); ws.addCell(labelC); labelC = new jxl.write.Label(7, rowIndex, "设立时间", headFormat); ws.addCell(labelC); labelC = new jxl.write.Label(8, rowIndex, "取消时间", headFormat); ws.addCell(labelC); ws.setColumnView(0, 12); ws.setColumnView(1, 8); ws.setColumnView(2, 12); ws.setColumnView(3, 3); ws.setColumnView(4, 12); ws.setColumnView(5, 8); ws.setColumnView(6, 12); ws.setColumnView(7, 10); ws.setColumnView(8, 10); ws.setRowView(rowIndex, 800); rowIndex = rowIndex + 1; // 下一行 Map map = custMap.get(i); String custName = map.get("custName").toString(); String custLicenceCode= map.get("custLicenceCode").toString(); String custAddress= map.get("custAddress").toString(); labelC = new jxl.write.Label(0, rowIndex, custName, cellFormat); ws.addCell(labelC); labelC = new jxl.write.Label(1, rowIndex, custLicenceCode, cellFormat); ws.addCell(labelC); labelC = new jxl.write.Label(2, rowIndex, custAddress, cellFormat); ws.addCell(labelC); String custCode = map.containsKey("custCode")? map.get("custCode").toString():""; List<Map> list = deliveryPointSearchService.getDeliveryPointAnchoredCustList(custCode); for(int j=0;j<list.size();j++){ Map mapTemp = list.get(j); labelC = new jxl.write.Label(3, rowIndex+j, String.valueOf(j+1), cellFormat); ws.addCell(labelC); String anchoredCustName = mapTemp.get("anchoredCustName").toString(); String anchoredLicenceCode = mapTemp.get("anchoredLicenceCode").toString(); String anchoredCustAddress = mapTemp.get("anchoredCustAddress").toString(); Date setTime = (Date)mapTemp.get("setTime"); String setTimeString = ""; if (setTime != null) { setTimeString = df.format(setTime); } Date cancelTime = mapTemp.containsKey("cancelTime")?(Date)mapTemp.get("cancelTime"):null; String cancelTimeString = ""; if (cancelTime != null) { cancelTimeString = df.format(cancelTime); } labelC = new jxl.write.Label(4, rowIndex+j, anchoredCustName, cellFormat); ws.addCell(labelC); labelC = new jxl.write.Label(5, rowIndex+j, anchoredLicenceCode, cellFormat); ws.addCell(labelC); labelC = new jxl.write.Label(6, rowIndex+j, anchoredCustAddress, cellFormat); ws.addCell(labelC); labelC = new jxl.write.Label(7, rowIndex+j, setTimeString, cellFormat); ws.addCell(labelC); labelC = new jxl.write.Label(8, rowIndex+j, cancelTimeString, cellFormat); ws.addCell(labelC); ws.setRowView(rowIndex+j, 800); } if(list.size()>0){ int temp = list.size()-1; ws.mergeCells(0, rowIndex, 0, rowIndex+temp); ws.mergeCells(1, rowIndex, 1, rowIndex+temp); ws.mergeCells(2, rowIndex, 2, rowIndex+temp); rowIndex = rowIndex+temp; } } wwb.write(); //关闭Excel工作薄对象 wwb.close(); os.close(); }catch (WriteException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
效果图:
发表评论
-
Mac系统下反编译jar包工具
2015-03-09 16:21 3471如题 -
string.format()
2014-06-26 09:45 1094Lua提供了string.format()函数来生成具有特定 ... -
java的3DES和DES加密和c代码
2013-08-02 09:32 6198情节: 多功能设备板子的密码键盘的调试程序 需要and ... -
linux 下java的串口,并口开发(RXTXcomm.jar)
2013-07-12 15:52 7166环境: 笔记本-虚拟机-红旗系统-实达金融手柄(串 ... -
eclipse 打包 jar 碰到的问题(包含第三方包)
2013-07-10 23:45 9887在window下做个java测试 ... -
java调用动态库dll和so库
2013-06-26 16:30 2667jni编程最原始的: e ... -
vector ,ArrayList
2013-03-15 11:45 948Vector 与 ArrayList 的区别 1.同步性 V ... -
java 反射
2013-03-15 11:15 867JAVA反射机制是在运行状 ... -
java.lang.Class类
2013-03-15 11:09 1090Java程序在运行时,Java运行时系统一直对所有的对象进行 ... -
Java的位运算符详解实例——与(&)、非(~)、或(|)、异或(^)
2013-01-23 10:15 1116哎,在学习计算机基础 ... -
java静态工厂方法
2011-04-21 09:13 1253创建类的实例最常见的是new 除此外还可以使用静态工厂方 ... -
关于java中的 sychronized 同步方法 与 同步块的理解
2011-03-18 15:41 1953首先,需要说明一点,也是最重要的一点,无论是同步方法 还是 同 ... -
java线程阻塞
2011-03-01 13:51 1983线程阻塞是指一个线程 ... -
关于java中乱码的总结
2011-02-20 22:54 1567java乱码是因为java和jsp ... -
最全的java面试题目二
2010-12-29 09:00 1207答:final—修饰符(关键字)如果一个类被声明为fin ... -
最全的java面试题目二
2010-12-29 08:58 1628答:final—修饰符(关键字)如果一个类被声明为fin ... -
最全的java面试题目一
2010-12-29 00:24 1641Java基础方面: 1、作用域public,priv ... -
java和c++的比较
2010-12-09 13:35 1236语法估计很挺多不同的地方,但是 主要是这两种开发者对内存地址变 ... -
java面试题目
2010-12-04 11:13 2177java基础面试题目,以备不时之需 ... -
设计模式-单例模式解析
2010-11-30 10:13 1155什么叫单例模型, 直接 ...
相关推荐
java用jxl包导出excel表格 x
JXL操作EXCEL公式,颜色,表格,百分比,小数点等等等等
通过java操作excel表格的工具类库 支持Excel 95-2000的所有版本 生成Excel 2000标准格式 支持字体、数字、日期操作 能够修饰单元格属性 支持图像和图表 应该说以上功能已经能够大致满足我们的需要。最...
Jxl是一个开源的Java Excel API项目,通过Jxl,Java可以很方便的操作微软的Excel文档。除了Jxl之外,还有Apache的一个POI项目,也可以操作Excel,两者相比之下:Jxl使用方便,但功能相对POI比较弱。POI使用复杂,...
通过java操作excel表格的工具类库 支持Excel 95-2000的所有版本 生成Excel 2000标准格式 支持字体、数字、日期操作 能够修饰单元格属性 支持图像和图表 应该说以上功能已经能够大致满足我们的需要...
至于Excel的写操作,对较高版本的Excel2007,POI提供了很好的支持,主要流程是第一步构建工作薄和电子表格对象,第二步在一个流中构建文本文件,第三步使用流中产生的数据替换模板中的电子表格。这种方式也可以处理...
通过js和jxl导出jsp页面的table表格到excel,兼容所有浏览器及复杂的table布局
21.1 应用JXL组件操作Excel 776 21.2 应用POI组件操作Excel 807 第22章 报表与打印 829 22.1 Web打印 830 22.2 利用Word打印报表 833 22.3 利用Excel打印报表 838 22.4 应用WebBrowser+CSS套打邮寄 22.5 打印库存...
21.1 应用JXL组件操作Excel 776 21.2 应用POI组件操作Excel 807 第22章 报表与打印 829 22.1 Web打印 830 22.2 利用Word打印报表 833 22.3 利用Excel打印报表 838 22.4 应用WebBrowser+CSS套打邮寄 22.5 打印库存...
需要把html页面中表格导出到excel的; 5. 需要在html页面中套打票据、报表的; 6. 需要在html页面中显示复杂报表,并要求精确打印预览及打印的; 7. 需要动态生成中国式复杂格式报表的; 8. 需要在html页面中输入...
4. 需要把html页面中表格导出到excel的; 5. 需要在html页面中套打票据、报表的; 6. 需要在html页面中显示复杂报表,并要求精确打印预览及打印的; 7. 需要动态生成中国式复杂格式报表的; 8. 需要在html页面中输入...