Reputation: 411
I am trying add html table in to the another word table' cell.
this is my code:
Tr workingRow = (Tr) XmlUtils.deepCopy(templateRow);
List<?> textElements = WMLPackageUtils.getTargetElements(workingRow, Text.class);
List<Tc> tcList = WMLPackageUtils.getTargetElements(workingRow, Tc.class);
Tc tc = WMLPackageUtils.getTc(tcList, "${Replace_Tex1}");
XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
XHTMLImporter.setParagraphFormatting(FormattingOption.IGNORE_CLASS);
XHTMLImporter.setTableFormatting(FormattingOption.IGNORE_CLASS);
for (Object object : textElements) {
Text text = (Text) object;
if (!text.getValue().equals("${Replace_Tex1}"))
continue;
String replacementValue = (String) replacements.get(text.getValue());
//text.setValue(replacementValue);
R r = (R) text.getParent();
r.getContent().clear();
r.getContent().addAll(XHTMLImporter.convert(replacementValue, null));
Upvotes: 1
Views: 1190
Reputation: 411
Hello i have fixed my code like that
R r = (R) text.getParent();
P paragraphOfText = wordMLPackage.getMainDocumentPart().createParagraphOfText("");
paragraphOfText.getContent().clear();
r.getContent().clear();eviewtable.getContent().add(new Tr(new Tc(itemTable, new Paragraph())));
tc.getContent().addAll(XHTMLImporter.convert(replacementValue, null));
tc.getContent().add(paragraphOfText);
it is working :) Thank you @JasonPlutext
Upvotes: 0
Reputation: 15863
I guess your problem is:
r.getContent().addAll(XHTMLImporter.convert(replacementValue, null));
Adding w:p (paragraph content) inside a run, which isn't allowed.
You can unzip your docx to look at word/document.xml
Upvotes: 1