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;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)