If the last emlement in document is std, append text with builder will be inserted in std element

1.zip (18.6 KB)

        var document = new Document("1.docx");
        var builder = new DocumentBuilder(document);
        builder.MoveToDocumentEnd();
        builder.Writeln("some text");
        document.Save("temp.docx");

the text “some text” will be inserted in std
part of document.xml of generated document
image.png (13.8 KB)

version:18.2.0.0

@qingyuan.ni,

Thanks for your inquiry. You are facing the expected behavior of Aspose.Words. Please use the following code example to get the desired output.

Document doc = new Document(MyDir + "1.docx");
                 
var builder = new DocumentBuilder(doc);
                
if (doc.LastSection.Body.LastChild.NodeType == NodeType.StructuredDocumentTag)
{
    doc.LastSection.Body.AppendParagraph("");
}
builder.MoveToDocumentEnd();
builder.Write("some text");

doc.Save(MyDir + "18.3.docx");