简体   繁体   English

使用Java在Excel中创建下拉菜单

[英]Create Dropdowns in Excel using java

I need to create Excel template from java. 我需要从Java创建Excel模板。 In that each cell should contain the dropdown values based on the header. 这样,每个单元格都应包含基于标题的下拉值。 These dropdowns and values will be populated from the java code.Please provide the sample code to create the Dropdowns. 这些下拉列表和值将从Java代码中填充。请提供示例代码以创建下拉列表。 And how to insert values into dropdowns.I am using poi for creating the Excel. 以及如何在下拉菜单中插入值。我使用poi创建Excel。

The below code sample gives the best resolution for my question. 下面的代码示例为我的问题提供了最佳解决方案。

CellRangeAddressList addressList = new CellRangeAddressList(0, 5, 0, 0);
        DVConstraint dvConstraint = DVConstraint
                .createExplicitListConstraint(new String[] { "10", "20", "30" });
        HSSFDataValidation dataValidation = new HSSFDataValidation(addressList,
                dvConstraint);
        dataValidation.setSuppressDropDownArrow(false);
        sheet.addValidationData(dataValidation);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM