tt

来源:互联网 发布:庄家收单软件 编辑:程序博客网 时间:2024/04/28 04:45
@Actionpublic void exportOrderEbayList() throws Exception {HttpServletResponse response = ServletActionContext.getResponse();HttpServletRequest request = ServletActionContext.getRequest();response.setCharacterEncoding("UTF-8");//迭代观察request有什么属性值/*Enumeration  enumeration = request.getParameterNames();while (enumeration.hasMoreElements()) {Object object = (Object) enumeration.nextElement();System.out.println("参数名="+object);}*///封装搜索条件this.setSearchMap(request);//被分装的搜索条件会以一个key-value的map集合存放在request中Map<String, String> map = (Map<String, String>) ServletActionContext.getRequest().getAttribute("setSearchMap");response.setContentType("application/vnd.ms-excel");String fileName = "ruleOrderEbayObject"+ DateUtils.dateToString8(new Date());List<RuleOrderEbayObject> listRule = ruleOrderEbayObjectService.getRuleEbayListForExport(map);/*List<RuleOrderEbayObject> listRule = ruleOrderEbayObjectService.getRuleEbayListImportTxt(map);*/OutputStream os = response.getOutputStream();WritableWorkbook wbook = Workbook.createWorkbook(os);// 建立excel文件WritableSheet wsheet = wbook.createSheet("已归档订单信息表", 0);// 工作表名称response.reset();// 清空输出流response.setHeader("Content-disposition", "attachment; filename="+ fileName + ".xls");// 设置Excel字体WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16,WritableFont.BOLD, false,jxl.format.UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);WritableCellFormat titleFormat = new WritableCellFormat(wfont);String[] title = {"Date", "buyer ID", "Transaction ID", "Name","country", "数量", "型号", "", "发货日期", "发货方式", "", "备注", "Team","", "", "recorded", "Address Line1", "Address Line","Town/City","State/Province/Region/County/Territory/Prefecture/Republic"," Zip/Postal Code", "仓库国家", "仓库", "状态", "", "account", "", "重发"};// 设置Excel表头for (int i = 0; i < title.length; i++) {Label excelTitle = new Label(i, 0, title[i], titleFormat);wsheet.addCell(excelTitle);}int totalOrderNum = 0;int totalGoodsNum = 0;if (null != listRule && listRule.size() > 0) {Map<String, Integer> itemMap = new HashMap<String, Integer>();for (int i = 1; i <= listRule.size(); i++) {totalOrderNum = totalOrderNum + 1;RuleOrderEbayObject wo = listRule.get(i - 1);itemMap.clear();totalGoodsNum = totalGoodsNum+ wo.getRuleOrderEbayObjectItem().size();for (RuleOrderEbayObjectItem item : wo.getRuleOrderEbayObjectItem()) {if (itemMap.get(item.getGoodsCode()) == null) {itemMap.put(item.getGoodsCode(), 1);} else {itemMap.put(item.getGoodsCode(),itemMap.get(item.getGoodsCode()) + 1);}}for (Map.Entry<String, Integer> en : itemMap.entrySet()) {// for(RuleOrderEbayObjectItem item :// wo.getRuleOrderEbayObjectItem()){if (wo.getCheckoutDate() != null) {Label content0 = new Label(0, i,wo.getCheckoutDate() == null? "": DateUtils.dateToString16(wo.getCheckoutDate()));wsheet.addCell(content0);}String address = wo.getShippingAddress();Label content1 = new Label(1, i, wo.getBuyerEmail());wsheet.addCell(content1);Label content2 = new Label(2, i, wo.getTransIds());wsheet.addCell(content2);Label content3 = new Label(3, i, wo.getBuyerFullName());wsheet.addCell(content3);Label content4 = new Label(4, i, wo.getTargetCountry());wsheet.addCell(content4);Label content5 = new Label(5, i, en.getValue() + "");wsheet.addCell(content5);Label content6 = new Label(6, i, en.getKey());wsheet.addCell(content6);Label content7 = new Label(7, i, "");wsheet.addCell(content7);Label content8 = new Label(8, i,DateUtils.dateToString18(new Date()));wsheet.addCell(content8);Label content9 = new Label(9, i, wo.getRulePostServer());wsheet.addCell(content9);Label content10 = new Label(10, i, "");wsheet.addCell(content10);Label content11 = new Label(11, i, wo.getRemark());wsheet.addCell(content11);Label content12 = new Label(12, i, "");wsheet.addCell(content12);Label content13 = new Label(13, i, "");wsheet.addCell(content13);if (wo.getCheckoutDate() != null) {Label content14 = new Label(14, i,DateUtils.dateToString18(wo.getCheckoutDate()));wsheet.addCell(content14);}Label content15 = new Label(15, i, "");wsheet.addCell(content15);Label content16 = new Label(16, i, wo.getStreet());wsheet.addCell(content16);Label content17 = new Label(17, i, wo.getStreet2());wsheet.addCell(content17);Label content18 = new Label(18, i, wo.getCity());wsheet.addCell(content18);Label content19 = new Label(19, i, address);wsheet.addCell(content19);Label content20 = new Label(20, i, wo.getZipCode());wsheet.addCell(content20);Label content21 = new Label(21, i, wo.getTargetCountry());wsheet.addCell(content21);Label content22 = new Label(22, i, wo.getSourceWarehouse());wsheet.addCell(content22);Label content23 = new Label(23, i, "已归档");wsheet.addCell(content23);Label content24 = new Label(24, i, "");wsheet.addCell(content24);Label content25 = new Label(25, i, wo.getAmount() + "");wsheet.addCell(content25);Label content26 = new Label(26, i, "");wsheet.addCell(content26);Label content27 = new Label(27, i, "");wsheet.addCell(content27);}}}WritableSheet totalSheet = wbook.createSheet("汇总", 1);totalSheet.addCell(new Label(0, 0, "订单总数:"));totalSheet.addCell(new Number(1, 0, totalOrderNum));totalSheet.addCell(new Label(2, 0, "货品总数:"));totalSheet.addCell(new Number(3, 0, totalGoodsNum));wbook.write();// 写入文件wbook.close();os.close();}

0 0
原创粉丝点击