C # Data export to Excel method summary see red part

Source: Internet
Author: User

 Public voidServiceorderexport (stringdata) {StringBuilder SB=NewStringBuilder (); Type EntityType=NULL; ; Propertyinfo[] Entityproperties=NULL; varinput = data. Deserializeobject<structserviceorder>(); using(varContext =srvdbhelper.datacontext) {sb. Remove (0, sb.                Length); varResults =context. Usp_srv_checkserviceorder (input. Serviceorderid, input. Acceptway, input. StatusCode, input. Description, input. Onelevelsortid, input. Twolevelsortid, input. Threelevelsortid, input. Ainsno, input. Acompanyname, input. Adepartmentid, input. Asectionid, input. AName, input. Cinsno, input. Ccompanyname, input. Cdepartmentid, input. Csectionid, input. Creatorname, input. Hinsno, input. Hcompanyname, input. Hdepartmentid, input. Hsectionid, input. Hname, input. CreateDate1, input. CreateDate2, input. FinishDate1, input. FinishDate2, input. Overduestatus1,input.                OVERDUESTATUS2); List<Usp_SRV_CheckServiceOrderResult> Entitys =NULL; if(Input. Hname! =NULL) {Entitys= ( fromIteminchResultswhereItem. Processing Person! =NULL                               Selectitem).                ToList (); }                Else{Entitys=results.                ToList (); }                //Check Entity collection cannot be empty                if(Entitys = =NULL|| Entitys. Count <1)                {                    return; }                //Remove all Propertie from the first entityEntityType = entitys[0].                GetType (); Entityproperties=entitytype.getproperties ();  for(inti =0; i < entityproperties.length; i++) {sb. Append (Entityproperties[i].                    Name); Sb. Append (","); } sb. Remove (sb.) Length-1,1); Sb. Append ("\ r \ n"); //Add all of the entity to the DataTable                foreach(ObjectEntityinchentitys) {                    //Check that all entities are of the same type                    if(Entity. GetType ()! =EntityType) {                        Throw NewException ("the collection element type to be converted is inconsistent"); }                    Object[] Entityvalues =New Object[Entityproperties.length];  for(inti =0; i < entityproperties.length; i++)                    {                        Try{Entityvalues[i]= Entityproperties[i]. GetValue (Entity,NULL); Sb. Append ("\""+ HttpContext.Current.Server.HtmlDecode (Entityvalues[i]. ToString (). Replace ("\"","\"\""). Replace ("\ n", Environment.NewLine). Replace ("<BR>", Environment.NewLine)) +"\""); Sb. Append (","); }                        Catch{Entityvalues[i]=string.                            Empty; Sb. Append ("\""+ Entityvalues[i]. ToString () +"\""); Sb. Append (","); }} sb. Remove (sb.) Length-1,1); Sb. Append ("\ r \ n");                } HttpResponse resp; Resp=System.Web.HttpContext.Current.Response; Resp. Charset="GB2312"; Resp. ContentEncoding= System.Text.Encoding.GetEncoding ("GB2312"); Resp. Appendheader ("content-disposition","attachment;filename="+string. Format ("{0:YYYYMMDDHHMMSS}", DateTime.Now) +". csv"); Resp.                Write (SB); Resp.            End (); }        }

C # Data export to Excel method summary see red part

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.