ASP. NET MVC uses Nopi to export Excel

Source: Internet
Author: User

<summary>///export admit//</summary>///<returns></returns>public ActionResult Exportadmitbanktrans (Banktransquerymodel querymodel) {Hssfworkbook WorkBook = new Hssfworkbook (); Isheet sheet = Workbook.createsheet ("business statement"); IRow row = sheet. CreateRow (0);//Get style func<icellstyle> Getcellstyle = () =>{icellstyle CellStyle = Workbook.createcellstyle (); Cellstyle.alignment =;return Cellstyle;};i CellStyle HeaderStyle = Getcellstyle (); IFont Fontheade = Workbook.createfont (); fontheade.fontheightinpoints = 11; Fontheade.fontname = "Microsoft Jas Black"; fontheade.boldweight = (short) fontboldweight.bold;headerstyle.setfont (FontHeade); func<string, int, icell> Setcellstyle = (string celltext, int colindex) =>{icell cell = row. Createcell (colindex); sheet. Setcolumnwidth (Colindex, 9000); cell. Setcellvalue (celltext); cell. CellStyle = Headerstyle;return cell;}; Setcellstyle ("Supplier name", 0), Setcellstyle ("Purchase number", 1), Setcellstyle ("actual to Account", 2) Setcellstyle ("Date of Account", 3); int Rowstart = 1;var list = BankTransBll.Instance.GetAllBankTransRealList (Querymodel), if (list! = null) {foreach (var item in List) {IRow myrow = sheet. CreateRow (Rowstart); myrow. Createcell (0). Setcellvalue (item.companyname); myrow. Createcell (1). Setcellvalue (item. CONTRACTNO); Myrow. Createcell (2). Setcellvalue (item. Amount.tostring ("F2")); Myrow. Createcell (3). Setcellvalue (item. Rec_createtime. ToShortDateString ()); rowstart++;}} using (MemoryStream ms = new MemoryStream ()) {workbook.write (MS); byte[] buffers = Ms. ToArray (); return File (buffers, "application/", String. Format ("{0}.xls", DateTime.Now.ToString ("Yyyymmddhhmmss")));}}


ASP. NET MVC uses Nopi to export Excel

Related Article

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: 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.