使用POI为多个列创建不同的下拉列表

时间:2013-07-02 12:01:08

标签: java excel drop-down-menu apache-poi multiple-columns

如何使用POI在Excel中为多列创建不同的下拉列表?我已尝试使用以下代码,但它不起作用:

{

CellRangeAddressList addressList = 
new CellRangeAddressList(1,10,columnIndexFromHeaderList,columnIndexFromHeaderList);

DVConstraint dvConstraint = 
DVConstraint.createExplicitListConstraint(stringArray);
dataValidation = new HSSFDataValidation(addressList,dvConstraint);                      
dataValidation.setSuppressDropDownArrow(false);

}

1 个答案:

答案 0 :(得分:1)

也许你还没有在表格中添加dataValidation ...请添加它...希望这会有用。

    {
       CellRangeAddressList addressList = 
       new CellRangeAddressList(1,10,columnIndexFromHeaderList,columnIndexFromHeaderList);
       DVConstraint dvConstraint = 
       DVConstraint.createExplicitListConstraint(stringArray);
       dataValidation = new HSSFDataValidation(addressList,dvConstraint);                      
       dataValidation.setSuppressDropDownArrow(false);
       sheet.addValidationData(dataValidation );

    }