2012-08-27 53 views
0

我想提供一個表格,如圖中所示。 在一列中應選擇日期。他們可以在圖片中看到我已經把日子當成了列表,但是,我想在一個單元格中選擇2天3天。 與我現在不工作。我只能在一個牢房裏選擇一天。Apache POI選擇一個單元格多個對象

enter image description here

我的代碼看起來如此。

 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天選擇 enter image description here

我有一個可視的BASIC代碼也gefindet。 我可以將此代碼更改爲Apache poi嗎?

我想作這樣 enter image description here

回答

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);