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