Java excel for paging data export

Source: Internet
Author: User

Java excel for paging data export

/*** Export an order (used for profit statistics) * @ 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 = "order export" + sdFormat. format (new Date (); fname = new String (fname. getBytes ("GBK"), "ISO_8859_1"); // file name {avoid garbled characters} response. setHeader ("Content-disposition", "attachment; filename =" + fname + ". csv "); // set the output file header response. setContentType ("text/csv"); response. setCharacterEncoding ("UTF-8"); OutputStream out = response. getOutputStream (); String sep = ","; // column name for (int column = 0; column
 
  
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 ("the order number is blank "). getBytes ();} out. write (sep ). getBytes (); if (! StringUtil. isNull (newOrderInfo. getMemberContactsPhone () {out. write (newOrderInfo. getMemberContactsPhone (). getBytes ();} else {out. write (String. valueOf ("the user's contact number is blank "). getBytes ();} out. write (sep ). getBytes (); if (newOrderInfo. getAddressDesc ()! = Null) {out. write (newOrderInfo. getAddressDesc (). getBytes ();} else {out. write (String. valueOf ("the contact address is blank "). 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 ("the order time is blank "). getBytes ();} out. write (System. getProperty ("line. separator "). getBytes ());}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.