I am working with OpenDope and Docx4j to repeat 2 rows of tables n no of times .
I am attaching the template docx . ContactDoc.zip .
it contains 2 rows , contact1 and contact 2 . I needs to repeat this rows n of times in the same order ,
say
contact1
contact2
contact1
contact2
..................
my custom xml structure look like ,
<contacts>
<contact1></contact1>
<contact2></contact2>
<contact1></contact1>
<contact2></contact2>
<contact1></contact1>
</contacts>
But after Opendope Preprocess , I am not getting the desired output , all the rows of contact1 and that of contact2 gets grouped together . as in output docx file Contactout.zip attached .
why is it so . I need to maintain the order of rows . there is no option in Opendope word Addin by which I cannot group together more that one row at a time . It allows only to bind 1 row at a time.
see the code below which uses to do preprocess
- Code: Select all
StringBuilder sb = generateXML();
try{
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
//Document doc = docBuilder.newDocument();
InputSource is = new InputSource( new StringReader( sb.toString() ) );
Document document = docBuilder.parse(is);
WordprocessingMLPackage wordMLPackage =
WordprocessingMLPackage.load(new File(System.getProperty("user.dir")
+ System.getProperty("file.separator") + "ContactDoc.docx"));
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
String itemId = CustomXmlUtils.getCustomXmlItemId(wordMLPackage).toLowerCase();
HashMap<String,CustomXmlDataStoragePart> parts= wordMLPackage.getCustomXmlDataStorageParts();
CustomXmlDataStoragePart customXmlDataStoragePart= wordMLPackage.getCustomXmlDataStorageParts().get(itemId);
customXmlDataStoragePart.getData().setDocument(document);
SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
// Process conditionals and repeats
OpenDoPEHandler odh = new OpenDoPEHandler(wordMLPackage);
odh.preprocess();
OpenDoPEIntegrity odi = new OpenDoPEIntegrity();
odi.process(wordMLPackage);
BindingHandler.applyBindings(wordMLPackage);
File save_bound = new File(System.getProperty("user.dir")
+ System.getProperty("file.separator") + "contactout.docx");
saver.save(save_bound);
}
public static StringBuilder generateXML(){
StringBuilder sb = new StringBuilder();
sb.append("\t\t<contacts>");
sb.append("\t\t<contact1>");
sb.append("</contact1>");
sb.append("\t\t<contact2>");
sb.append("</contact2>");
sb.append("\t\t<contact1>");
sb.append("</contact1>");
sb.append("\t\t<contact2>");
sb.append("</contact2>");
sb.append("</contacts>");
return sb;
}
Kindly help in as early as possible to solve this ....