0

我想提供一张桌子,如图所示。在列中应选择天数。他们可以在图片中看到我已经将天数作为列表,但是,添加我想在单元格中选择 2 3 天。对我来说现在这行不通。我只能在牢房中选择一天。

在此处输入图像描述

我的代码看起来如此。

     static void addDayChooserConstraint2Cell(Sheet sheet, int rowNumber,
        int columnNumber) {
    DataValidationHelper dvHelper = sheet.getDataValidationHelper();
    DataValidationConstraint dvConstraint = dvHelper
            .createExplicitListConstraint(daysOfWeek());
    CellRangeAddressList addressList = new CellRangeAddressList(1, rowNumber,   columnNumber, columnNumber);
    DataValidation validation = dvHelper.createValidation(dvConstraint,
            addressList);
    validation.setShowErrorBox(true);
    sheet.addValidationData(validation);
}



static String[] daysOfWeek(){
    String[] daysOfWeek=new String[]{
            "MONDAY",
            "TUESDAY",
            "WEDNESDAY",
            "THURSDAY",
            "FRIDAY",
            "SATURDAY", 
            "SUNDAY"
    };
    return daysOfWeek;
}

你可以在图片中看到,我只能选择一天。我想在一个单元格中选择超过 1 天 在此处输入图像描述

我也有一个可视化的 BASIC 代码 gefindet。我可以将此代码更改为 Apache poi 吗?

我想这样做 在此处输入图像描述

4

1 回答 1

3
//this might help u
CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
DVConstraint dvConstraint = DVConstraint .createExplicitListConstraint(new String[] { "Ann", "Ben", "Cam" });
DataValidation dataValidation = new HSSFDataValidation(addressList,dvConstraint);
dataValidation.setSuppressDropDownArrow(false);
sheet.addValidationData(dataValidation);
于 2012-08-28T02:37:44.743 回答