aspose words for java 24.2表格数据填充之后报错,请看下什么原因,怎么解决?
4.3.zip (1.6 MB)
@SalesDhorde 请使用以下代码来保留分节符:
/// <summary>
/// Inserts content of the external document after the specified node.
/// </summary>
/// <param name="insertionDestination">Node in the destination document after which the content
/// Should be inserted. This node should be a block level node (paragraph or table).</param>
/// <param name="docToInsert">The document to insert.</param>
private static void insertDocument(Node insertionDestination, Document docToInsert) {
if (!((insertionDestination.getNodeType() == NodeType.PARAGRAPH) || (insertionDestination.getNodeType() == NodeType.TABLE)))
throw new IllegalArgumentException("The destination node should be either a paragraph or table.");
CompositeNode destinationParent = insertionDestination.getParentNode();
NodeImporter importer =
new NodeImporter(docToInsert, insertionDestination.getDocument(), ImportFormatMode.KEEP_SOURCE_FORMATTING);
Document dstDoc = (Document) destinationParent.getDocument();
Body body = (Body) destinationParent;
Section dstSection = body.getParentSection();
DocumentBuilder builder = new DocumentBuilder(dstDoc);
int index = dstDoc.getSections().indexOf(dstSection);
if (docToInsert.getSections().getCount() > 1) {
builder.moveToSection(index);
builder.moveToParagraph(dstSection.getBody().getParagraphs().indexOf(insertionDestination), -1);
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
}
// Loop through all block-level nodes in the section's body,
// then clone and insert every node that is not the last empty paragraph of a section.
for (Section srcSection : docToInsert.getSections()) {
if (srcSection.equals(docToInsert.getFirstSection())) {
for (Node srcNode : srcSection.getBody()) {
if (srcNode.getNodeType() == NodeType.PARAGRAPH)
{
Paragraph para = (Paragraph)srcNode;
if (para.isEndOfSection() && !para.hasChildNodes())
continue;
}
Node newNode = importer.importNode(srcNode, true);
destinationParent.insertAfter(newNode, insertionDestination);
insertionDestination = newNode;
}
} else {
Node newNode = importer.importNode(srcSection, true);
dstDoc.getSections().insert(index + 1, newNode);
}
}
}
非常感谢,可以了,但不支持双重嵌套到表格中、