【发布时间】:2019-05-22 12:46:33
【问题描述】:
我正在尝试将 html 表格添加到另一个单词表格的单元格中。
- 我可以将 html 表格添加到另一个单词表格的单元格中。 (好的)
- 我可以生成最后一个word文档调用lastDocument.docx(OK)
- 我无法再次加载 WordprocessingMLPackage.load(lastDocument.docx),抛出这个 异常 Docx4j 意外元素 (uri:"http://schemas.openxmlformats.org/wordprocessingml/2006/main", 本地:“p”)
这是我的代码:
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));
【问题讨论】:
标签: html-table openxml docx4j