Thanks Nick, I'm going for plan B which is to use the Word merge-record feature. If I add mergerec fields into my document and then point it to a CSV file with the needed data to be inserted into my document, it seems to work. Only issue now is that Word puts up a popup dialog warning me I am grabbing data from an outside source and should I allow that.
Anyway to turn that off? Thanks Bart On Mar 7, 2013, at 4:42 PM, Nick Burch <[email protected]> wrote: > 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: [email protected] > For additional commands, e-mail: [email protected] >
smime.p7s
Description: S/MIME cryptographic signature
