11
我需要使用Apache POI在Excel文件中創建一個下拉列表。我可以這樣做但是 我無法將下拉列表中的第一項作爲默認項目。Excel下拉列表使用Apache POI
public class sd {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
DataValidation dataValidation = null;
DataValidationConstraint constraint = null;
DataValidationHelper validationHelper = null;
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet1=(XSSFSheet) wb.createSheet("sheet1");
validationHelper=new XSSFDataValidationHelper(sheet1);
CellRangeAddressList addressList = new CellRangeAddressList(0,5,0,0);
constraint =validationHelper.createExplicitListConstraint(new String[]{"SELECT","10", "20", "30"});
dataValidation = validationHelper.createValidation(constraint, addressList);
dataValidation.setSuppressDropDownArrow(true);
sheet1.addValidationData(dataValidation);
FileOutputStream fileOut = new FileOutputStream("c:\\temp\\vineet.xlsx");
wb.write(fileOut);
fileOut.close();
}
}
但是,這不是作爲下拉列表中的一個選項。如果我們需要它在列表中呢?說「SELECT」應該作爲列表中的默認值。 – zeewagon