0

我在我的工作簿对象中添加了一个自定义属性,例如:

((XSSFWorkbook)workBook).getProperties().getCustomProperties().addProperty("fileNameSuffix" , "testName");

现在我怎么能再读一遍。
为什么没有这样的方法getProperty(String key)

4

2 回答 2

4

你的意思是像POIXMLProperties.CustomProperties.getProperty(String)方法吗?我认为这应该做你想要的。好吧,假设您使用的是足够新的 Apache POI 版本,至少可以拥有它!

但是,请注意它返回一个 CTProperty 对象,该对象相当低级,并且没有显式类型。您必须调用各种isSetXXX方法来确定它是什么类型,然后getXXX获取值。

在POIXMLPropertiesTextExtractor中有一个如何做到这一点的例子

于 2014-09-03T14:24:37.607 回答
0

我想办法做到这一点,但我真的不喜欢这种方式

    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
    }
于 2014-09-03T13:35:13.643 回答