apache-poicustom-properties

apache poi read custom property


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) ?


Solution

  • 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
        }