java分頁資料匯出excel,java資料匯出excel

來源:互聯網
上載者:User

java分頁資料匯出excel,java資料匯出excel

/** * 訂單匯出(用於統計利潤) * @return */public String orderExport() throws IOException{if (queryOrderList_currentPage == null || queryOrderList_currentPage <= 0) {queryOrderList_currentPage = 1;}OrderInfo order = new OrderInfo();if (!StringUtil.isNull(queryOrderList_orderStatus)) {order.setOrderStatus(queryOrderList_orderStatus);}if (!StringUtil.isNull(queryOrderList_orderCard)) {order.setOrderCard(queryOrderList_orderCard);}if (!StringUtil.isNull(queryOrderList_memberPhone)) {order.setMemberPhone(queryOrderList_memberPhone);}if (!StringUtil.isNull(queryOrderList_memberContactsPhone)) {order.setMemberContactsPhone(queryOrderList_memberContactsPhone);}if (queryOrderList_businessId != null && queryOrderList_businessId > 0) {order.setBusinessId(queryOrderList_businessId);}if (!StringUtil.isNull(queryOrderList_addressDesc)) {order.setAddressDesc(queryOrderList_addressDesc);}if (!StringUtil.isNull(queryOrderList_beginTime) && !StringUtil.isNull(queryOrderList_endTime)) {order.setBeginTime(queryOrderList_beginTime);order.setEndTime(queryOrderList_endTime);}try {HttpServletResponse response = ServletActionContext.getResponse();queryOrderList_pageBean = statisticsService.queryOrderListByCompanyConditions(order,queryOrderList_currentPage, queryOrderList_pageSize);int totalPage = queryOrderList_pageBean.getTotalPage();response.reset(); SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");String fname= "訂單匯出"+sdFormat.format(new Date());fname=new String(fname.getBytes("GBK"),"ISO_8859_1");//檔案名稱{避免出現亂碼} response.setHeader("Content-disposition", "attachment; filename="+fname+".csv");// 設定輸出檔案頭response.setContentType("text/csv"); response.setCharacterEncoding("UTF-8"); OutputStream out = response.getOutputStream();String sep = ","; //列名for(int column=0;column<CompanyConfig.ORDER_EXPORT_COLUMN.split(",").length;column++){out.write(CompanyConfig.ORDER_EXPORT_COLUMN.split(",")[column].getBytes()); out.write(sep.getBytes()); }//分行符號out.write(System.getProperty("line.separator").getBytes());//資料OrderInfo newOrderInfo =new OrderInfo();if(queryOrderList_pageBean.getList()!=null && queryOrderList_pageBean.getList().size()>0){for (int i = 0; i < queryOrderList_pageBean.getList().size(); i++) {newOrderInfo=(OrderInfo)queryOrderList_pageBean.getList().get(i);getOut(out,newOrderInfo,sep);}}if(totalPage>1){for (int m = 2; m <= totalPage; m++) {queryOrderList_pageBean = statisticsService.queryOrderListByCompanyConditions(order, queryOrderList_currentPage, queryOrderList_pageSize);List list =queryOrderList_pageBean.getList();if(list!=null && list.size()>0){for (int j = 0; j < list.size(); j++){OrderInfo nOrderInfo=(OrderInfo)list.get(j);getOut(out, nOrderInfo, sep);} }}}out.flush(); out.close();} catch (Exception e) {e.printStackTrace();}        return null;}public void getOut(OutputStream out,OrderInfo newOrderInfo,String sep) throws IOException{if(!StringUtil.isNull(newOrderInfo.getOrderCard())){out.write(String.valueOf(newOrderInfo.getOrderCard()).getBytes()); }else{out.write(String.valueOf("訂單編號為空白").getBytes()); }out.write((sep).getBytes());if(!StringUtil.isNull(newOrderInfo.getMemberContactsPhone())){out.write(newOrderInfo.getMemberContactsPhone().getBytes()); }else{out.write(String.valueOf("使用者聯絡電話為空白").getBytes());}out.write((sep).getBytes()); if(newOrderInfo.getAddressDesc()!=null){out.write(newOrderInfo.getAddressDesc().getBytes());}else{out.write(String.valueOf("聯絡地址為空白").getBytes());}out.write((sep).getBytes()); if(newOrderInfo.getGenerateTime()!=null){out.write(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(newOrderInfo.getGenerateTime()).getBytes());}else{out.write(String.valueOf("下單時間為空白").getBytes());}out.write(System.getProperty("line.separator").getBytes());}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.