You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Daniel Ferreira Castro <da...@avantiprima.com.br> on 2013/06/20 22:21:27 UTC

Doubt updating a DOCX

People,

I am having difficutiles tryiing to save a document - DOCX - with the
updated value of some custom properties.

I read the custom properties
I update the value of the custom properties
I save the file with the updated values of custom properties.
When I open the saved fil on word 2007 the file open with the old value of
the custom properties and I need to right click over the filed and manually
update field.  My goal is to avoid this last step, so when I open the saved
file it already shows the actual value of the properties.

I have no idea how to do it.  I looked around internet, but nothing found.

This is the code that I am running.

public static void main(String[] args) throws IOException {
OPCPackage ocpackage =
POIXMLDocument.openPackage("C:\\Users\\ctd527\\Desktop\\final.docx");
XWPFDocument doc = new XWPFDocument(ocpackage);
FileOutputStream out = new
FileOutputStream("c:\\Users\\ctd527\\Desktop\\final-1.docx");
CustomProperties props = doc.getProperties().getCustomProperties();
List <CTProperty> ctp = props.getUnderlyingProperties().getPropertyList();
POIXMLProperties.ExtendedProperties ext = doc.getProperties()
.getExtendedProperties();
ext.getUnderlyingProperties().setApplication("Microsoft Office Word");
for (CTProperty foo : ctp) {
System.out.println(foo.toString());
foo.setLpwstr("TEST");
System.out.println(foo.toString());
}
 //POIXMLDocument.openPackage(path).
doc.write(out);
    out.close();
}

-- 
Atenciosamente,
Daniel Ferreira Castro

Arquiteto JEE
ITIL Foundations, BEA Enterprise Architect, BEA Portal Solutions, BEA Build
Solutions, SOA Implementation Champion, SOA Support Champion