FIX: Download Excel file, automatically download aspx with Thunderbolt

Source: Internet
Author: User

FIX: Download Excel file, automatically download aspx with Thunderbolt

If(request.querystring["ID"] !=NULL&&!string. IsNullOrEmpty (request.querystring["ID"]. ToString ())) {if(request.querystring["OID"] !=NULL&&!string. IsNullOrEmpty (request.querystring["OID"]. ToString ())) {ID= request.querystring["ID"]. ToString (); OID= request.querystring["OID"]. ToString (); stringSqlwhere =string. Format ("pproductnumber= ' {0} ' and ordersnumber= ' {1} '", ID, OID); List<SonOrders> li=_sonordersmanager.getorderslists (Sqlwhere); if(Li. Count >0&&li!=NULL) {MemoryStream ms=NewMemoryStream (); Iworkbook Workbook=NewHssfworkbook (); Isheet sheet=workbook. Createsheet (); Icellstyle Style1=workbook. Createcellstyle (); IFont Font=workbook. CreateFont (); Font. Fontheightinpoints= One; Style1. SetFont (font); Sheet. Defaultrowheight= -* -; for(inti =0; I <9; i++) { if(i = =0) sheet. Setcolumnwidth (i, -* the); Elsesheet. Setcolumnwidth (i, at* the); Sheet. Setdefaultcolumnstyle (i, style1); } IRow row1= Sheet. CreateRow (0); Icell Cell= Row1. Createcell (0); Cell. Setcellvalue (OID+"_ Status Detail"); Icellstyle Style2=workbook. Createcellstyle (); Style2. Alignment=HorizontalAlignment.Center; IFont Font2=workbook. CreateFont (); Font2. Fontheight= -* -; Style2. SetFont (Font2); Cell. CellStyle=Style2; Sheet. Addmergedregion (NewCellrangeaddress (0,0,0,7)); IRow HeaderRow= Sheet. CreateRow (1); Headerrow.createcell (0). Setcellvalue ("Product number"); Headerrow.createcell (1). Setcellvalue ("Time of order"); Headerrow.createcell (2). Setcellvalue ("Prototype Acceptance Time"); Headerrow.createcell (3). Setcellvalue ("first item acceptance time"); Headerrow.createcell (4). Setcellvalue ("Assembly Acceptance Time"); Headerrow.createcell (5). Setcellvalue ("factory out of stock time"); Headerrow.createcell (6). Setcellvalue ("On- site storage time"); Headerrow.createcell (7). Setcellvalue ("pick-In time"); Headerrow.createcell (8). Setcellvalue ("Open Box Acceptance time"); Headerrow.createcell (9). Setcellvalue ("Installation Completion Time"); Headerrow.createcell (Ten). Setcellvalue ("Installation Acceptance Time"); intj =2; foreach(Sonorders soinchli) {IRow dataRow= Sheet. CreateRow (j + +); Datarow.createcell (0). Setcellvalue (So. Sproductnumber); Datarow.createcell (1). Setcellvalue (Gettimes ("Time of order", so. Sproductnumber). ToString ()); Datarow.createcell (2). Setcellvalue (Gettimes ("Prototype Acceptance Time", so. Sproductnumber). ToString ()); Datarow.createcell (3). Setcellvalue (Gettimes ("first item acceptance time", so. Sproductnumber). ToString ()); Datarow.createcell (4). Setcellvalue (Gettimes ("Assembly Acceptance Time", so. Sproductnumber). ToString ()); Datarow.createcell (5). Setcellvalue (Gettimes ("factory out of stock time", so. Sproductnumber). ToString ()); Datarow.createcell (6). Setcellvalue (Gettimes ("On- site storage time", so. Sproductnumber). ToString ()); Datarow.createcell (7). Setcellvalue (Gettimes ("pick-In time", so. Sproductnumber). ToString ()); Datarow.createcell (8). Setcellvalue (Gettimes ("Open Box Acceptance time", so. Sproductnumber). ToString ()); Datarow.createcell (9). Setcellvalue (Gettimes ("Installation Completion Time", so. Sproductnumber). ToString ()); Datarow.createcell (Ten). Setcellvalue (Gettimes ("Installation Acceptance Time", so. Sproductnumber). ToString ()); } workbook. Write (MS); Ms. Flush (); Ms. Position=0; Try { string[] files = directory.getfiles (System.AppDomain.CurrentDomain.BaseDirectory +"excels/"); foreach(stringFileinchfiles) {File.delete (File); } } Catch(Exception Exx) {Response.Write (Exx. Message.tostring ()); } string pname = "state verbose _" + DateTime.Now.ToString ("YYYYMMDDHHMMSS") + ". xls"; Npoihelper.savetofile (MS, System.AppDomain.CurrentDomain.BaseDirectory + "excels/" + pname); Response.Redirect ("~/excels/" + PName, false); Response.Clear (); //Response.Clear (); //response.clearheaders (); //Response.Buffer = false; //Response.ContentType = "Application/octet-stream"; //if (Request.Browser.Browser = = "Firefox")//System.Web.HttpContext.Current.Response.AppendHeader ("Content-disposition", "attachment;filename=" + oid + "_ Status verbose. xls "); //Else//System.Web.HttpContext.Current.Response.AppendHeader ("Content-disposition", "attachment;filename=" + Httputility.urlencode (oid + "_ State verbose. xls", System.Text.Encoding.UTF8)); //System.Web.HttpContext.Current.Response.AppendHeader ("Content-length", Ms. Length.tostring ()); //System.Web.HttpContext.Current.Response.BinaryWrite (Ms. GetBuffer ()); //System.Web.HttpContext.Current.Response.Flush (); //System.Web.HttpContext.Current.Response.End (); } }

FIX: Download Excel file, automatically download aspx with Thunderbolt

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.