如何通过使用Apache POI删除Excel的数据验证。我有以下代码。在第一次运行时,将正确创建下拉列表,但是一旦我以字符串列表中的不同值再次运行该程序,该下拉列表就不会得到更新。
FileInputStream fsIP= new FileInputStream(new File("D:\\template3.xls")); //Read the spreadsheet that needs to be updated
HSSFWorkbook wb = new HSSFWorkbook(fsIP); //Access the workbook
HSSFSheet worksheet = wb.getSheetAt(0); //Access the worksheet, so that we can update / modify it.
// System.out.println(worksheet.getRow(1).getCell(2));
Cell cell = null; // declare a Cell object
DataValidation dataValidation = null;
DataValidationConstraint constraint = null;
DataValidationHelper validationHelper = null;
CellRangeAddressList addressList = new CellRangeAddressList(0,5,0,5);
//cell = worksheet.getRow(2).getCell(2); // Access the second cell in second row to update the value
DVConstraint dvConstraint = DVConstraint.createExplicitListConstraint(new String[]{"124", "20", "30"});
dataValidation = new HSSFDataValidation(addressList, dvConstraint);
dataValidation.setSuppressDropDownArrow(false);
worksheet.addValidationData(dataValidation);
// cell.setCellValue("OverRide Last Name"); // Get current cell value value and overwrite the value
fsIP.close(); //Close the InputStream
FileOutputStream output_file =new FileOutputStream(new File("D:\\template3.xls")); //Open FileOutputStream to write updates
wb.write(output_file); //write changes
output_file.close(); //close the stream
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1037 次 |
| 最近记录: |