Read drop down list content from Excel using apache poi

后端 未结 2 1069
小鲜肉
小鲜肉 2020-12-10 16:34

I need to create a drop down list (Data Validation) on a particular cell in an Excel sheet and read them back.

With the help of tutorials provided by Apache PO

2条回答
  •  一整个雨季
    2020-12-10 16:53

    I can't seem to find any mechanism in HSSF to retrieve the DataValidations from the HSSFSheet. So if you have a .xls file, you're out of luck.

    However, if you have a .xlsx file, then XSSFSheet supplies a method to retrieve a list of all XSSFDataValidations on the sheet: getDataValidations, which returns a List.

    You'll need to loop over them all, calling regions() to examine the CellRangeAddressList to see if it applies to your cell. If it does, then call getValidationConstraint to access the DataValidationConstraint object, on which you can call getExplicitListValues to get the array of strings back.

提交回复
热议问题