poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Burch <apa...@gagravarr.org>
Subject Re: How to modify the document core property "Keywords"?
Date Thu, 07 Mar 2013 21:42:29 GMT
On Thu, 7 Mar 2013, Bart Jenkins wrote:
> I'm trying to pass in a version string to a field code in some 
> boilerplate docx file that I read in at startup.  For example:
>
> XWPFDocument document = new XWPFDocument(new FileInputStream("c:\template.docx");
> CoreProperties coreprops = document.getProperties().getCoreProperties();
> coreprops.setKeywords("Version 1.0");

That looks write to change the OOXML level properties

> And in my "template.docx" document, I've got a field code that looks 
> like the following:
>
> {INFO Keywords xxx \* MERGEFORMAT}    // <-- this is how it looks with the field code
toggled ON in the word document.
>
> The 3rd line of code above (coreprops.setKeywords()) does not fail and 
> if I re-read the coreprops variable I see that it gets updated.  But the 
> value is NOT showing up in my document.

The office file formats contain caching at various points for performance 
reasons. For example, Excel caches formula values, which often catches out 
people new to POI.

Word also caches property values, which is what's biting you here. In 
fact, you can see that by loading a copy of word, going into the document 
properties, and changing them. In most versions of word, with many common 
settings, the property won't change in the text, until you trigger an 
update properties call (right click then update property, if memory serves 
- I don't have word to hand)

Sadly, that means you too need to update the cached properties in your 
word document after the change. It's likely a common problem though, so if 
you do manage to write some code to process the word document and update 
the values of all the properties it finds, please do share it back!

Nick

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


Mime
View raw message