Package Npoi exporting Excel with drop-down list

Source: Internet
Author: User

1  /// <summary>2         ///ways to bind data3         /// </summary>4         /// <param name= "Ssfworkbook" >Hssfworkbook</param>5         /// <param name= "Sheet1" >Hssfsheet</param>6         /// <param name= "Catedt" >Data Source</param>7         /// <param name= "SheetName" >page name</param>8         /// <param name= "Dispname" >Display Name</param>9         /// <param name= "Row" >falls into the first few columns</param>Ten         /// <param name= "Nextcount" >The position of the next column (as long as there is 1, followed by 1, and so on)</param> One         Private voidGetcategorydata (Hssfworkbook Ssfworkbook, Hssfsheet Sheet1, DataTable Catedt,stringSheetName,stringDispname,intRowintnextcount) A         { -             Try -             { theHssfsheet Sheet2 = Ssfworkbook. Createsheet ("Sht"+sheetname); -                 intIndexcate =0; -Ssfworkbook. Setsheethidden (Row-nextcount,true);//Hidden -  +                 foreach(DataRow Cateiteminchcatedt.rows) -                 { +Sheet2. CreateRow (indexcate). Createcell (0). Setcellvalue (Cateitem[dispname]. ToString ());//column Data Aindexcate++; at                 } -Hssfname range = Ssfworkbook. Createname ();//Create a name -Range. Reference ="Sht"+ SheetName +"! $A $: $A $"+ indexcate;//format -Range. NameName =SheetName; -  -                 //Add a drop-down list inCellrangeaddresslist regions =NULL; -Regions =NewCellrangeaddresslist (1,65535, Row-1, Row-1); toDvconstraint constraint =Dvconstraint.createformulalistconstraint (sheetname); +Hssfdatavalidation datavalidate =NewHssfdatavalidation (regions, constraint); - Sheet1. Addvalidationdata (datavalidate); the             } *             Catch { } $}
1    /// <summary>2         ///Set Excel Header (array length must be the same)3         /// </summary>4         /// <param name= "StrName" >the name in Excel</param>5         /// <param name= "width" >Wide</param>6         /// <param name= "HeaderRow" >Hssfrow</param>7         /// <param name= "Sheet1" >Hssfsheet</param>8         /// <param name= "Hssfworkbook" >Ssfworkbook</param>9         Private stringSetupexceltitle (Hssfworkbook Ssfworkbook,string[] StrName,int[] width, hssfrow headerrow, Hssfsheet Sheet1)Ten         { One             Try A             { -                 if(Strname.length! =width. Length) -                 { the                     return "array length is different! "; -                 } -Hssffont Fonttitle =Ssfworkbook. CreateFont (); -Fonttitle.fontheightinpoints = One; +Fonttitle.boldweight =Hssffont.boldweight_normal; -Hssfcellstyle Hssfcelltitle =Ssfworkbook. Createcellstyle (); + Hssfcelltitle.setfont (fonttitle); A  at                  for(inti =0; i < strname.length; i++) -                 { -                     //set up the table header - Headerrow.createcell (i). Setcellvalue (Strname[i]); -                     //to set the width of a table header - Sheet1. Setcolumnwidth (i, width[i]); inHeaderrow.getcell (i). CellStyle =Hssfcelltitle; -                 } to                 return "OK"; +             } -             Catch(Exception ex) the             { *                 returnEx. Message; $             }Panax Notoginseng}
1  /// <summary>2         ///set up Excel content3         /// </summary>4         /// <param name= "values" >content</param>5         /// <param name= "DataRow" >Hssfrow</param>6         Private voidSetupexcelcontent (string[] values, Hssfrow dataRow)7         {8              for(inti =0; I < values. Length; i++)9             {Ten                 //Populating Data One Datarow.createcell (i). Setcellvalue (Values[i]); A             } -}

Package Npoi exporting Excel with drop-down list

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.