Java POI Excel Action drop-down menu and data validation

Source: Internet
Author: User


1 PrivateInputStream UPDATETEMPLATESTYLEHSSF (InputStream inputstream,cscustcon Cscustcon)throwsIOException, daoexception{2Hssfworkbook Workbook =NewHssfworkbook (InputStream); 3Hssfsheet firstsheet= workbook.getsheetat (0);4List<string> strlist=Csconaccedao.getaccenameandnolistbyconid (Cscustcon);5String[] strs= (string[]) Strlist.toarray (Newstring[strlist.size ()]);6 7String secondsheetname= "Contract attachment name and number";8Hssfsheet secondsheet=Workbook.createsheet (secondsheetname);9 if(NULL!=strs&&strs.length>0){Ten for(inti=0;i<strs.length;i++){ OneHssfrow row=Secondsheet.createrow (i); AHssfcell cell= Row.createcell (0); - Cell.setcellvalue (Strs[i]); - } the } -Name name=workbook.createname (); - Name.setnamename (secondsheetname); -Name.setreferstoformula (secondsheetname+ "! $A $: $A $" +strs.length); +Cellrangeaddresslist newstylerange=NewCellrangeaddresslist (1,65535,0,0); -Dvconstraint constraint=Dvconstraint.createformulalistconstraint (secondsheetname); +Hssfdatavalidation datavalidation=Newhssfdatavalidation (Newstylerange, constraint); ADatavalidation.setshowpromptbox (true); at Firstsheet.addvalidationdata (datavalidation); - -Bytearrayoutputstream out=NewBytearrayoutputstream (); - Workbook.write (out); - byte[] contents=Out.tobytearray (); -InputStream newinputstream=NewBytearrayinputstream (contents); in returnNewinputstream; -}

Requirements Description: Excel first page first column drop-down menu data is displayed on the second page

If you delete one item on the second page, save the data in the first column drop-down menu on the first page.

List<string> Strlist=csconaccedao.getaccenameandnolistbyconid (Cscustcon);

This line of code returns the data from the drop-down menu

Parameters

The file object generated by InputStream InputStream for the file object   is the corresponding Excel generated by the parsed

Bytearrayoutputstream out=New  bytearrayoutputstream ();         Workbook.write (out);          byte [] contents=Out.tobytearray ();         InputStream newinputstreamnew  bytearrayinputstream (contents);               return Newinputstream;

This snippet of code is updated after the Excel file is re-saved

Other:

Hssfworkbook  objects can handle only 2003 and previous versions
Xssfworkbook Object  

Java POI Excel Action drop-down menu and data validation

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.