Page 1 of 1

Can I insert html at predefined positions in my template?

PostPosted: Wed May 12, 2010 2:55 pm
by vikrant
What is the template support in docx4j, I tried to use the following code to include the html at ${ScreenShot} in my word doc, but it didnt seem to work:

AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/hw.html"));
afiPart.setBinaryData(Docx4JExample.getContents("C:/DATA/Workspaces/UIToolingRCP/com.csc.fs.accel.ui.wordexport/a.html").getBytes());
afiPart.setContentType(new ContentType("text/html"));
Relationship altChunkRel = wordMLPackage.getMainDocumentPart().addTargetPart(afiPart);
CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
ac.setId(altChunkRel.getId());
String includeHTML = XmlUtils.marshaltoString(ac, true);
System.out.println(includeHTML);
mappings.put("ScreenShot", includeHTML);

Thanks in advance for the help.

Re: Can I insert html at predefined positions in my template?

PostPosted: Wed May 12, 2010 3:47 pm
by vikrant
I was able to insert the HTML in my template at predefined location. The problem was we cannot have altChunk element inside <w:t>, it can be only added as a sibling of <w:p>, I manipulated document.xml to have the ${ScreenShot} text as a sibling of <w:p> and then used the code given in previous post to add the html I wanted.


I am still wondering how to apply external stylesheet to the html inside word.

Re: Can I insert html at predefined positions in my template

PostPosted: Wed Oct 12, 2011 5:12 am
by benpoole
I realise this is over a year later, but how did you achieve this replacement? My understanding is that you can't swap out a w:t node for w:altchunk so I'm interested to know how you did this. In my tests, if I move a ${TAG} in the document.xml file so that it is not nested in either a w:p or a w:t node, it is simply ignored, and the altChunk is not added to the document.