Hello,
Aspose Version: 15.8.0
please see attached documents for clarification:
- Document_WithContentControl_4Aspose.docx: Base document
- ParagraphWithFormatting.docx: Imported document
- outInsert.docx: Result, with addition of manual copy/paste to compare
When using the code below to import data into an inline SDT, all run formatting of this paragraph is ignored. Only the paragraph formatting is used.
Wenn using word copy/paste (strg+a,c,v) to insert the data into the SDT, exactly the opposite behaviour can be observed.
Is there a way to reproduce word behaviour?
Thanks,
Alexander
public void shouldTestImportParagraphIntoSdt() throws Exception {
Path tempDirPath = Files.createTempDirectory("shouldTestImportParagraphIntoSdt");
String tempDir = tempDirPath + File.separator;
System.out.println(tempDirPath);
Document doc1 = new Document(getResourceAsStream(RESOURCE_DOCX_TEXT_WithContentControl4Aspose));
Document doc2 = new Document(getResourceAsStream(RESOURCE_DOCX_PARAGRAPHWITHFORMATTING));
// Remofe Aspose Watermark to properly test formatting;
doc2.getFirstSection().getBody().getFirstParagraph().remove();
DocumentBuilder documentBuilder = new DocumentBuilder(doc1);
NodeCollection collection = doc1.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true);
for (StructuredDocumentTag sdt : collection) {
switch (sdt.getTag()) {
case "sdtBlock":
sdt.removeAllChildren();
Paragraph para = new Paragraph(doc1);
sdt.appendChild(para);
documentBuilder.moveTo(para);
documentBuilder.insertDocument(doc2, ImportFormatMode.USE_DESTINATION_STYLES);
break;
case "sdtInline":
sdt.removeAllChildren();
Run r = new Run(doc1);
sdt.appendChild®;
documentBuilder.moveTo®;
documentBuilder.insertDocument(doc2, ImportFormatMode.USE_DESTINATION_STYLES);
break;
}
}
public Node insertDocument(Document srcDoc, int importFormatMode) throws java.lang.Exception
Inserts content of the document into the current position of DocumentBuilder’s cursor.
This method mimics the MS Word behavior, as if CTRL+‘A’ (select all content) was pressed, then CTRL+‘C’ (copy selected into the buffer) inside one document and then CTRL+‘V’ (insert content from the buffer) inside another document.
Parameters:
srcDoc - Source document for inserting.
importFormatMode - A ImportFormatMode value. Specifies how to merge style formatting that clashes.
Returns:
First inserted node.