You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Thomas P Laford <Th...@raytheon.com> on 2010/08/27 19:10:05 UTC

Reading XLSM custom Properties

I have the following code to read the custom properties of an XLS file 
(pre-Office 2007):

        // Open the Excel file
        //
        FileInputStream xlsFileStream = new FileInputStream(listFile[i]);
        HSSFWorkbook wb = new HSSFWorkbook(xlsFileStream);
        ExcelExtractor txex1 = new ExcelExtractor(wb);

        // Extract the custom properties from the workbook
        //
        DocumentSummaryInformation dsi = txex1.getDocSummaryInformation();
        CustomProperties properties = dsi.getCustomProperties();
        if (properties != null)
        {
                Object prop = properties.get("My Property");
                if (prop != null)
                {
                        myProperty = prop.toString();
                }
        }

But now I need to enhance this to read the same properties from an XLSM 
file (Office 2007+)

        // Open the Excel file
        //
        FileInputStream xlsFileStream = new FileInputStream(listFile[i]);
        XSSFWorkbook wb = new XSSFWorkbook(xlsFileStream);
        XSSFExcelExtractor txex1 = new XSSFExcelExtractor(wb);

        // Extract the custom properties from the workbook
        //
        DocumentSummaryInformation dsi = txex1.getDocSummaryInformation();
        CustomProperties properties = dsi.getCustomProperties();
        if (properties != null)
        {
                Object prop = properties.get("My Property");
                if (prop != null)
                {
                        myProperty = prop.toString();
                }
        }

But the XSSLExcelExtractor does not have a method to retrieve the Document 
Summary info.  Am I missing something fundamental about the differences in 
the pre-2007 and post 2007 office files?

Re: Reading XLSM custom Properties

Posted by Nick Burch <ni...@alfresco.com>.
On Wed, 8 Sep 2010, Thomas P Laford wrote:
> Nick,  I downloaded the v3.6 source code and looked at the detail of the
> POIXMLPropertiesTextExtractor class.  The method I think I want to emulate
> is getCustomPropertiesText().

That looks the right place

> Alas, the most important piece (getting the custom property value) is 
> TBD.

Yes, seems so. First, I'd suggest you create a simple file with a few 
custom properties in it. Please upload this to a new bug in bugzilla, 
along with details of the properties set, so we've got something to test 
against once the feature is implemented

Next, unzip the file (.xlsx is a zip file of xml files), and track down 
your custom properties. Take a look and see how they have been stored. 
Finally, make use of the xmlbeans objects for them (see the 
getCustomPropertiesText method for how to get them), and get at your 
required text. The xmlbeans objects very closely map to the xml, so once 
you can see how it is stored in the xml, it should be easy to get at the 
bean

Finally, please do then fix up the missing bit of 
POIXMLPropertiesTextExtractor armed with your knowledge of custom 
properties, and submit a patch :)

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Reading XLSM custom Properties

Posted by Thomas P Laford <Th...@raytheon.com>.
Nick,  I downloaded the v3.6 source code and looked at the detail of the 
POIXMLPropertiesTextExtractor class.  The method I think I want to emulate 
is getCustomPropertiesText().

        public String getCustomPropertiesText()
        {
                StringBuffer text = new StringBuffer();
 
org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties
                        props = 
getDocument().getProperties().getCustomProperties().getUnderlyingProperties();

                CTProperty[] properties = props.getPropertyArray();
                for(int i = 0; i<properties.length; i++) 
                {
                        // TODO - finish off
                        String val = "(not implemented!)";

                        text.append(properties[i].getName() + " = " + val 
+ "\n");
                }

                return text.toString();
        }

Alas, the most important piece (getting the custom property value) is TBD.

Is this where you recommended I look, or have I gone to the wrong spot?



From:
Nick Burch <ni...@alfresco.com>
To:
POI Users List <us...@poi.apache.org>
Date:
08/27/2010 01:15 PM
Subject:
Re: Reading XLSM custom Properties



On Fri, 27 Aug 2010, Thomas P Laford wrote:
> But the XSSLExcelExtractor does not have a method to retrieve the 
> Document Summary info.  Am I missing something fundamental about the 
> differences in the pre-2007 and post 2007 office files?

Alas the two file formats store their properties in a very very different 
way...

I'd suggest you take a look at POIXMLPropertiesTextExtractor, which should 

be a good example for how to work with the OOXML properties

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org

Re: Reading XLSM custom Properties

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 27 Aug 2010, Thomas P Laford wrote:
> OK.  I can use my XSSFExcelExtractor instance in the 
> POIXMLTextExtractor's constructor, and I can use that 
> POIXMLTextExtractor instance in the POIXMLPropertiesTextExtractor's 
> constructor.  But I still don't see a method to specify a "key" string 
> and retrieve the associated property value.

You want to look at the source code for POIXMLPropertiesTextExtractor - 
it'll show you how to go about working with the ooxml properties

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Reading XLSM custom Properties

Posted by Thomas P Laford <Th...@Raytheon.com>.
OK.  I can use my XSSFExcelExtractor instance in the POIXMLTextExtractor's 
constructor, and I can use that POIXMLTextExtractor instance in the 
POIXMLPropertiesTextExtractor's constructor.  But I still don't see a 
method to specify a "key" string and retrieve the associated property 
value.

Re: Reading XLSM custom Properties

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 27 Aug 2010, Thomas P Laford wrote:
> But the XSSLExcelExtractor does not have a method to retrieve the 
> Document Summary info.  Am I missing something fundamental about the 
> differences in the pre-2007 and post 2007 office files?

Alas the two file formats store their properties in a very very different 
way...

I'd suggest you take a look at POIXMLPropertiesTextExtractor, which should 
be a good example for how to work with the OOXML properties

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org