Npoi solution drop-down list String literals in formulas can & #39; t be bigger than 255 Chars ASCII, npoiliterals

Source: Internet
Author: User

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

Code:

1 public static void dropDownList (string [] datas, string filePath) 2 {3 HSSFWorkbook workbook = new HSSFWorkbook (); 4 ISheet sheet = workbook. createSheet ("drop-down list test"); 5 ISheet hidden = workbook. createSheet ("hidden"); 6 // the data source sheet page does not display 7 workbooks. setSheetHidden (workbook. getSheetIndex (hidden), true); 8 ICellStyle style = workbook. createCellStyle (); 9 style. dataFormat = HSSFDataFormat. getBuiltinFormat (" 0 "); 10 style. alignment = HorizontalAlignment. center; 11 style. verticalAlignment = verticalignment. center; 12 IRow row = null; 13 ICell cell = null; 14 for (int I = 0; I <datas. length; I ++) 15 {16 row = hidden. createRow (I); 17 cell = row. createCell (0); 18 cell. setCellValue (datas [I]); 19} 20 IName namedCell = workbook. createName (); 21 namedCell. nameName = "hidden"; 22 namedCell. refersToFormula = "hidden! A $1: A $ "+ datas. length; 23 HSSFDataValidationHelper dvHelper = new HSSFDataValidationHelper (sheet as HSSFSheet); 24 IDataValidationConstraint dvConstraint = (IDataValidationConstraint) dvHelper. createFormulaListConstraint ("hidden"); 25 CellRangeAddressList addressList = null; 26 HSSFDataValidation validation = null; 27 for (int I = 0; I <datas. length; I ++) 28 {29 row = sheet. createRow (I); 30 cell = row. createCell (0); 31 cell. cellStyle = style; 32 addressList = new CellRangeAddressList (I, I, 0, 0); 33 validation = (HSSFDataValidation) dvHelper. createValidation (dvConstraint, addressList); 34 sheet. addValidationData (validation); 35} 36 37 FileStream stream = new FileStream (filePath, FileMode. openOrCreate); 38 workbook. write (stream); 39 stream. close (); 40}View Code

Call:

 1 static void Main(string[] args) 2 { 3     int max = 100; 4     string[] datas = new string[max]; 5     for (int i = 0; i < max; i++) 6     { 7         datas[i] = "" + i; 8     } 9 10     string filePath = @"F:\\test.xls";11     dropDownList(datas, filePath);12 13     Console.Read();14 }

 

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