We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert table (or anything) at very end of document

I’m trying to determine how to add a table at the end of the last page of a word document and not having much luck.

I’m using the doc as a template (for reporting) and I already have the table created in Word, and the content is static. What I need to do is simply move it from where it currently is in Word and move it to the end of the document. This should not be difficult, but admittedly I’m struggling with it.

What is the general approach to moving existing nodes around to “random” locations?

Any help will be appreciated.

Hi Ken,

Thanks for your inquiry. You can use the following two lines to move the cursor to the end of document.

DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();

https://docs.aspose.com/words/net/navigation-with-cursor/

I hope, this helps.

Best regards,

I had tried that, but still no luck.
That indeed moves the cursor to the end but doesn’t help me move a table/node to the end.

For example, I reference a pre-existing table with:

var mytable = doc.GetChildNodes(NodeType.Table, true)[0];

Then I want to move that table to the end of the document. Moving the cursor doesn’t (at least for me so far) doesn’t help me.

Thoughts?

Hi Ken,

Thanks for your inquiry. Please see attached input/output sample documents and try executing the following code:

Document doc = new Document(MyDir + @"in.docx");
Table tab = doc.FirstSection.Body.Tables[0];
Paragraph lastPara = doc.LastSection.Body.LastParagraph;
lastPara.ParentNode.InsertAfter(tab, lastPara);
doc.Save(MyDir + @"out.docx");

I hope, this helps.

Best regards,