"14th article" Easyui DataGrid export Excel

Source: Internet
Author: User

<class= "btn Btn-app"  onclick= "Exportexcel ()"><  class = "fa fa-edit" ></i > Export Excel   </a>

Paste the following code before I want to say

My data is the primary foreign key relationship, there are multiple tables associated, so when doing the data, found a lot of problems, read, it will automatically read all the data.

Of course this does not meet the requirements after I export, I just need to export the fields I want, so I did the data processing.

 //Export Excel    functionExportexcel () {varrows = $ ("#saleGrid"). DataGrid ("GetRows");  for(vari = 0; i < rows.length; i++) {//for data processing            if(IsArray (rows[i). Organizedid)) {rows[i]. Organizedid= Rows[i]. Organizedid[0]; }            if(IsArray (rows[i). CustomerId)) {rows[i]. CustomerId= Rows[i]. Customerid[0]; }            if(Rows[i]. Advancedate! =NULL) {                varUNIX = Rows[i]. Advancedate.replace ("/date (", ""). Replace (")/", ""); varUN = unix.substring (0, 10); varNewdate =NewDate (); Newdate.settime (UN* 1000); Rows[i]. Advancedate=newdate.tolocalestring (); }            if(Rows[i]. OrderDate! =NULL) {                varUNIX = Rows[i]. Orderdate.replace ("/date (", ""). Replace (")/", ""); varUN = unix.substring (0, 10); varNewdate =NewDate (); Newdate.settime (UN* 1000); Rows[i]. OrderDate=newdate.tolocalestring (); }            if(Rows[i]. Retainagedate! =NULL) {                varUNIX = Rows[i]. Retainagedate.replace ("/date (", ""). Replace (")/", ""); varUN = unix.substring (0, 10); varNewdate =NewDate (); Newdate.settime (UN* 1000); Rows[i]. Retainagedate=newdate.tolocalestring (); }            //Remove the fields you don't want            DeleteRows[i].            Saleatts; DeleteRows[i].            Saleorderid; DeleteRows[i].            Saleorderitems; DeleteRows[i].            Salestatus; DeleteRows[i].            UserName; DeleteRows[i].            Customer; DeleteRows[i].        Adddate; }        varBodydata = json.stringify (rows);//turn into a JSON string        //Replace Chinese title        varA = Bodydata.replace (/saleorderno/g, "Order Number"). Replace (/ordertype/g, order type). replace (/fromwhere/g, "Order origin"). Replace (/organizedid/g, "agency"). Replace (/saleuser/g, "Salesperson"). Replace (/saletc/g, "Sales commission"). Replace (/orderdate/g, ' Order Date ')). Replace (/contractno/g, "contract number"). Replace (/amount/g, "Total"). Replace (/advance/g, "first payment"). Replace (/advancedate/g, "first payment date"). Replace (/paymethod/g, "payment Method"). Replace (/retainage/g, "tail"). Replace (/retainagedate/g, "End Date"). Replace (/inlayprice/g, "Mosaic"). Replace (/custmanager/g, "account Manager"). Replace (/equityno/g, "share book Number"). Replace (/logisticstotal/g, "logistics costs"). Replace (/remarks/g, "Remarks"). Replace (/completedstatus/g, "status"). Replace (/customerid/g, "End Customer"); varPostData ={data:a}; $.ajax ({type:"POST", URL:"Exportexcel", Data:postdata, success:function(data) {if(data = = "1")) {layer.msg ("The operation succeeds, the file is on the desktop!" ", {icon:6, Time:2000,                    }); } Else if(data = = "-1")) {layer.msg ("The operation failed!" ", {Icon:2 });    }            }        }); }
        /// <summary>        ///Export Excel/// </summary>        /// <returns></returns>         PublicActionResult Exportexcel () {stringJSON = request.params["Data"]; Try{DataTable dt=excelhelper.jsontodatatable (JSON); stringPathdestop =Environment.getfolderpath (Environment.SpecialFolder.Desktop); Excelhelper.gridtoexcelbynpoi (DT, Pathdestop+"\\"+"Sales Order-"+ DateTime.Now.ToString ("YYYY-MM-DD") +"Export"+". xls"); returnContent ("1"); }            Catch(Exception) {returnContent ("-1"); }        }

After export

---------------------------------------------------------------------------------------------------------

Reprint please remember the author and source Oh-.-
Kingdudu
Original source: http://www.cnblogs.com/kingdudu/p/4863980.html

---------------------------------------------------------------------------------------------------------

"14th article" Easyui DataGrid export Excel

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.