1

I have added a custom property to my workbook object like:

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

Now how can I read it back again.
Why there is no such method as getProperty(String key) ?

Soosh
  • 812
  • 1
  • 8
  • 24

2 Answers2

4

Do you mean like the method POIXMLProperties.CustomProperties.getProperty(String)? I think that should do what you want. Well, assuming you're on a new enough version of Apache POI to have it at least!

However, do note that it returns a CTProperty object, which is fairly low-level, and doesn't have an explicit type on it. You'll have to call the various isSetXXX methods to work out what kind it is, then getXXX to get the value.

There's an example of how to do that in POIXMLPropertiesTextExtractor

Márk Farkas
  • 1,426
  • 1
  • 12
  • 25
Gagravarr
  • 47,320
  • 10
  • 111
  • 156
0

I figure a way to do it, but I do not really like it this way

    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
    }
Soosh
  • 812
  • 1
  • 8
  • 24