我在我的工作簿对象中添加了一个自定义属性,例如:
((XSSFWorkbook)workBook).getProperties().getCustomProperties().addProperty("fileNameSuffix" , "testName");
现在我怎么能再读一遍。
为什么没有这样的方法getProperty(String key)
?
我在我的工作簿对象中添加了一个自定义属性,例如:
((XSSFWorkbook)workBook).getProperties().getCustomProperties().addProperty("fileNameSuffix" , "testName");
现在我怎么能再读一遍。
为什么没有这样的方法getProperty(String key)
?
你的意思是像POIXMLProperties.CustomProperties.getProperty(String)方法吗?我认为这应该做你想要的。好吧,假设您使用的是足够新的 Apache POI 版本,至少可以拥有它!
但是,请注意它返回一个 CTProperty 对象,该对象相当低级,并且没有显式类型。您必须调用各种isSetXXX
方法来确定它是什么类型,然后getXXX
获取值。
在POIXMLPropertiesTextExtractor中有一个如何做到这一点的例子
我想办法做到这一点,但我真的不喜欢这种方式
List<CTProperty> customProperties = workBook.getProperties().getCustomProperties().getUnderlyingProperties().getPropertyList();
String fileNameSuffix = "";
for(int i = 0 ; i < customProperties.size() ; i++) {
CTProperty property = customProperties.get(i);
if (customProperties.get(i).getName().equals("testName"))
fileNameSuffix = property.getLpwstr(); // getLpwstr() will return the value of the property
}