I have attached two files here. original is having one text and one shape but text substitution has removed the oval shape. I tried the same thing with a complex document which has tables, checkboxes etc. but in this document the oval shape has been preserved and gave the expected output.
The original namespaces were:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
mc:Ignorable="w14 wp14">
<w:body>
But after text substitution it converted to:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
xmlns:ns7="http://schemas.openxmlformats.org/schemaLibrary/2006/main"
xmlns:ns8="http://schemas.openxmlformats.org/drawingml/2006/chart"
xmlns:ns9="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing"
xmlns:ns10="http://schemas.openxmlformats.org/drawingml/2006/diagram"
xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
xmlns:ns12="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:ns15="http://opendope.org/xpaths"
xmlns:ns16="http://opendope.org/conditions"
xmlns:ns17="http://opendope.org/questions"
xmlns:ns18="http://opendope.org/components"
xmlns:ns19="http://schemas.openxmlformats.org/drawingml/2006/compatibility"
xmlns:ns20="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas">
<w:body>
For text substitution I have tried both the ways
1) searched the placeholders and substituted values
- Code: Select all
List<Object> jaxbNodesViaXPath = documentMainPart.getJAXBNodesViaXPath("//w:t", false);
String xml = XmlUtils.marshaltoString(wmlDocumentEl, false);
Document document = (Document) XmlUtils.unmarshallFromTemplate(xml, tagValues);
2) iterating on
- Code: Select all
wmlDocumentEl.getBody().getEGBlockLevelElts()
for paragraph and table nodes and replacing text using
- Code: Select all
textNode.setValue("RED")
I have used Office 2010 for creating the original document and for docx4j 2.6.0 and 2.7.0Snapshot are tried out.