使用Apache POI从Excel读取下拉列表内容

使用Apache POI从Excel读取下拉列表内容,第1张

使用Apache POI从Excel读取下拉列表内容

DataValidation甚至存储在HSSF工作簿中,但是它在

InternalSheet
该库中,并且由于
private
这样,对它的访问权不提供给应用程序程序员。我已经使用Java Reflection
API访问内部工作表。这段代码对我来说很好用。

private ArrayList<DVRecord> init(FileInputStream fis) throws InvalidFormatException, IOException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {    HSSFWorkbook hWorkbook = (HSSFWorkbook) WorkbookFactory.create(fis);    HSSFSheet hSheet = hWorkbook.getSheetAt(1); // sheet on which you want to read data validation    Class c = org.apache.poi.hssf.usermodel.HSSFSheet.class;    Field field = c.getDeclaredField("_sheet");    field.setAccessible(true);    Object internalSheet = field.get(hSheet);    InternalSheet is = (InternalSheet) internalSheet;    DataValidityTable dvTable = is.getOrCreateDataValidityTable();    Class c2 = org.apache.poi.hssf.record.aggregates.DataValidityTable.class;    Field field2 = c2.getDeclaredField("_validationList");    field2.setAccessible(true);    Object records = field2.get(dvTable);    ArrayList<DVRecord> dvRecords = (ArrayList<DVRecord>) records;    return dvRecords;}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5428542.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存