Page 1 of 1

Performing template find-and-replace on pages

PostPosted: Sat Jan 23, 2016 9:39 am
by WorldsEndless
I'm writing a (clojure) web-app that needs to generate a title page based on a template. I'm trying to follow instructions like these https://dzone.com/articles/create-complex-word-docx, but they seem to be badly out-dated (e.g. I'm getting "P" objects instead of "Text" objects, and have no setContent method available). Can someone tell me what the current method to do this is, or where I can go to find it?

Re: Performing template find-and-replace on pages

PostPosted: Mon Jan 25, 2016 9:55 pm
by jason
WorldsEndless wrote:I'm getting "P" objects instead of "Text" objects


Text objects sit inside run (R) objects, which sit within paragraphs (P). Nothing has changed here.

WorldsEndless wrote:have no setContent method available


That's available in your main document part object, in recent versions of docx4j:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        /**
         * Set the  contents of this part.
         * (Just an alias/synonym for setJaxbElement())
         * @param jaxbElement
         * @since 3.0
         */

        public void setContents(E jaxbElement) {
                this.jaxbElement = jaxbElement;
        }
       
 
Parsed in 0.020 seconds, using GeSHi 1.0.8.4


In general, I'd recommend you create the content you want in Word (ie your title page), then generate code based on that using the docx4j webapp or Helper Word Add-In.