我有一个下拉列表包含一些选项,例如两个单元格。我需要的是关于所选选项将一个单元格变为可编辑,另一个变为只读,反之亦然。
FileOutputStream fos;
try {
fos = new FileOutputStream("D:\\POIXls.xls");
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("new Sheet");
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
DataValidationConstraint dvConstraint =
dvHelper.createExplicitListConstraint(new String[] { "cell 1 edit","cell 2 edit"});
CellRangeAddressList addressList = new CellRangeAddressList(0, 2, 0, 0);
DataValidation validation = dvHelper.createValidation(dvConstraint, addressList);
if (validation instanceof XSSFDataValidation) {
validation.setSuppressDropDownArrow(true);
validation.setShowErrorBox(true);
} else {
validation.setSuppressDropDownArrow(false);
}
sheet.addValidationData(validation);
workbook.write(fos);
fos.flush();
fos.close();
}catch(Exception e){//catch code}
我需要知道如何根据用户的选择使该 xls 文件使这些单元格可编辑/只读。VB 代码也可能有帮助。