Npoi Resolving drop-down list String literals in formulas can ' t be bigger than 255 Chars ASCII

Source: Internet
Author: User

Code:

1  Public Static voidDropDownList (string[] datas,stringFilePath)2 {3Hssfworkbook Workbook =NewHssfworkbook ();4Isheet sheet = workbook. Createsheet ("Drop- down list test");5Isheet hidden = workbook. Createsheet ("Hidden");6     //Data Source Sheet page does not display7Workbook. Setsheethidden (workbook. Getsheetindex (Hidden),true);8Icellstyle style =workbook. Createcellstyle ();9Style. DataFormat = Hssfdataformat.getbuiltinformat ("0");TenStyle. Alignment =HorizontalAlignment.Center; OneStyle. VerticalAlignment =Verticalalignment.center; AIRow row =NULL; -Icell cell =NULL; -      for(inti =0; I < datas. Length; i++) the     { -row =hidden. CreateRow (i); -Cell = row. Createcell (0); - cell. Setcellvalue (Datas[i]); +     } -Iname Namedcell =workbook. Createname (); +Namedcell.namename ="Hidden"; ANamedcell.referstoformula ="hidden! a$1:a$"+datas. Length; atHssfdatavalidationhelper Dvhelper =NewHssfdatavalidationhelper (sheet ashssfsheet); -Idatavalidationconstraint dvconstraint = (idatavalidationconstraint) dvhelper.createformulalistconstraint ("Hidden"); -Cellrangeaddresslist AddressList =NULL; -hssfdatavalidation validation =NULL; -      for(inti =0; I < datas. Length; i++) -     { inrow =sheet. CreateRow (i); -Cell = row. Createcell (0); toCell. CellStyle =style; +AddressList =NewCellrangeaddresslist (i, I,0,0); -validation =(hssfdatavalidation) dvhelper.createvalidation (Dvconstraint, AddressList); the sheet. Addvalidationdata (validation); *     } $ Panax NotoginsengFileStream stream =NewFileStream (FilePath, filemode.openorcreate); - workbook. Write (stream); the Stream. Close (); +}
View Code

Call:

1 Static voidMain (string[] args)2 {3     intMax = -;4     string[] Datas =New string[Max];5      for(inti =0; i < Max; i++)6     {7Datas[i] =""+i;8     }9 Ten     stringFilePath =@"F:\\test.xls"; One dropDownList (datas, filePath); A  - Console.read (); -}

Npoi Resolving drop-down list String literals in formulas can ' t be bigger than 255 Chars ASCII

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.