You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Rahul Dev Vardhan <ra...@newgen.co.in> on 2011/10/03 16:02:07 UTC

Problem in editing the custom properties of Office 2007+ files.

We are editing the custom properties of a document as mentioned in the below code,

      FileInputStream fis = new FileInputStream(sourceFile);
        POIFSFileSystem fileSystem = new POIFSFileSystem(fis);
        fis.close();
        DirectoryEntry entry = fileSystem.getRoot();
        
        DocumentEntry siEntry = (DocumentEntry) entry.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
        DocumentInputStream dis = new DocumentInputStream(siEntry);
        PropertySet isPropertySet = new PropertySet(dis);
        dis.close();
        SummaryInformation si = new SummaryInformation(isPropertySet);
        
        DocumentEntry dsiEntry = (DocumentEntry) entry.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
        DocumentInputStream ddis = new DocumentInputStream(dsiEntry);
        PropertySet disPropertySet = new PropertySet(ddis);
        ddis.close();
        DocumentSummaryInformation dsi = new DocumentSummaryInformation(disPropertySet);
        CustomProperties properties = dsi.getCustomProperties();
        if(properties == null) {
            properties = new CustomProperties();
        }
        properties.put("ImgdDocumentOraseq", "47384378");
        dsi.setCustomProperties(properties);
        si.setAuthor("RD");
        si.setComments("78787877");
        si.write(entry, SummaryInformation.DEFAULT_STREAM_NAME);
        dsi.write(entry, DocumentSummaryInformation.DEFAULT_STREAM_NAME);
        FileOutputStream os = new FileOutputStream(sourceFile);
        fileSystem.writeFilesystem(os);
        os.close();

It works fine for .doc, .xls and .ppt files, but i am not able to implement the same functionality for .docx, .xlsx and .ppts files.

Please let me know your comments regarding the same.

Thanks & Regards,
Rahul Dev Vardhan 
Disclaimer :- This e-mail and any attachment may contain confidential, proprietary or legally privileged information. If you are not the original intended recipient and have erroneously received this message, you are prohibited from using, copying, altering or disclosing the content of this message. Please delete it immediately and notify the sender. Newgen Software Technologies Ltd (NSTL)  accepts no responsibilities for loss or damage arising from the use of the information transmitted by this email including damages from virus and further acknowledges that no binding nature of the message shall be implied or assumed unless the sender does so expressly with due authority of NSTL.



Re: Problem in editing the custom properties of Office 2007+ files.

Posted by Nick Burch <ni...@alfresco.com>.
On Mon, 3 Oct 2011, Rahul Dev Vardhan wrote:
> It works fine for .doc, .xls and .ppt files, but i am not able to 
> implement the same functionality for .docx, .xlsx and .ppts files.

Nope, the OOXML file formats use a very different container, and 
properties are stored in a totally different manner

The usermodel classes for DOCX, XLSX and PPTX all extends from 
POIXMLDocument which provide a way to get at the properties. (Alternately, 
you can just create a POIXMLProperties class for a OPCPackage). From this, 
you can get at the various kinds of properties, and read/write/add them

I'm not sure if we have any examples for writing them (and if not, please 
do submit an example when you're done!). We do have a good example for 
reading though, in the form of POIXMLPropertiesTextExtractor

Nick

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