Java – use Apache POI to read the contents of the drop-down list from excel

I need to create a drop-down list (data validation) on a specific cell in the excel worksheet and read it back

With the help of the tutorial provided by Apache POI, I can create a drop-down list in the excel worksheet, but I also need to read the contents of the drop-down list when reading again so that I can render the drop-down list on a similar drop-down UI

Any suggestions?

Solution

I can't seem to find any mechanism in HSSF to retrieve data validations from HSSF sheet So if you have one Xls files, then you're out of luck

But if you have Xlsx file, xssfsheet provides a method to retrieve the list of all xssfdatavalidations on the worksheet: getdatavalidations, which returns list < xssfdatavalidation >

You need to go through all this and call regions () to check the cellrangeaddresslist to see if it applies to your cell If so, call getvalidationconstraint to access the datavalidationconstraint object on which you can call getexplicitlistvalues to get a string array

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>