Poi operation excel, create a drop-down box

Source: Internet
Author: User
/*****/Package test. excel;/*** @ author seven * 09:15:23 */import Java. io. fileoutputstream; import Java. util. date; import Org. apache. poi. hssf. usermodel. dvconstraint; import Org. apache. poi. hssf. usermodel. hssfcell; import Org. apache. poi. hssf. usermodel. hssfdatavalidation; import Org. apache. poi. hssf. usermodel. hssfrow; import Org. apache. poi. hssf. usermodel. hssfsheet; import Org. apache. poi. hssf. usermodel. hssfworkbook; import Org. apache. poi. hssf. util. cellrangeaddresslist; public class poi {public static void main (string [] ARGs) {string [] list = {"Neusoft", "Huaxin", "sap", "Hai Hui "}; new poi (). createlistbox (list); return;} public void createlistbox (string [] list) {// file initialization hssfworkbook WB = new hssfworkbook (); hssfsheet sheet = WB. createsheet ("new sheet"); // insert hssfrow ROW = sheet in the first cell of the first row. createrow (0); hssfcell cell = row. createcell (0); // cell for normal write operations. setcellvalue ("select"); // This is an experiment // generate a drop-down list // only valid for cells () cellrangeaddresslist regions = new cellrangeaddresslist (0, 0, 0, 0, 0); // generate the content dvconstraint constraint = dvconstraint in the drop-down box. createexplicitlistconstraint (list); // bind the drop-down box and hssfdatavalidation data_validation = new hssfdatavalidation (regions, constraint); // apply sheet to the sheet page. addvalidationdata (data_validation); // write fileoutputstream fileout; try {fileout = new fileoutputstream ("workbook.xls"); WB. write (fileout); fileout. close ();} catch (exception e) {// todo auto-generated catch blocke. printstacktrace ();} // end system. out. println ("over ");}}

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.