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

Free Support Forum - aspose.com

How to Select an insertion point of empty space in word document

The beolw code is written using Microsoft.interop.Word and i want to replace with Aspose.Word in .Net

Word._Application Word_Application = new Word.Application();
Word._Document Word_Document = Word_Application.Documents.Add(ref DefaultTemplate);
 Word.Selection Word_Selection = Word_Application.Selection;  //Selecting empty space of document //
Word_Selection.InsertFile(SourceFile);Word_Document.SaveAs(ref Word_Selection.InsertFile(SourceFile,OutputFile)

Using Aspose I’m unable to select the empty area of document like how Interop is doing,
Please help me on this.


Please note that Aspose.Words is quite different from the Microsoft Word’s Object Model in that it represents the document as a tree of objects more like an XML DOM tree. If you worked with any XML DOM library you will find it is easy to understand and work with Aspose.Words. When you load a Word document into Aspose.Words, it builds its DOM and all document elements and formatting are simply loaded into memory. Please read the following article for more information on DOM.

Please refer to the following article about inserting a document into another document.

Could you please ZIP and attach your input and expected output Word documents along with some detail of your requirement? We will then guide you according to your requirement.

Currently, I am facing the following problem: I have certain text in our documents which are in specific formats. I am using the Selection object of MS Word, using which we replace the selected text with the actual value.
I am not able to find a class similar to the selection class of MS Word. Could you please suggest which class object should be created.


Please ZIP and attach your sample input and expected output Word documents here for our reference. We will then provide you code example according to your requirement.

Aspose.zip (71.3 KB)

Please find the above attachment, template and data document should merge and creates a final document and that final document will convert to pdf like as attached output file.
No customizations for the template document like adding bookmarks of any replaceable keywords to insert data at particular place


In your case, we suggest you following solution.

  1. Import both documents into Aspose.Words’ DOM
  2. Get the table from data.doc using Document.GetChild method.
  3. Get the node from template.dot after which you want to insert table.
  4. Use NodeImporter.ImportNode method to import table from one document into another.
  5. Remove the empty rows.
  6. Remove the empty paragraphs if you want.

Following code example shows how to achieve the desired output. Hope this helps you.

var data = new Document(MyDir + "Data.doc");
var template = new Document(MyDir + "Tempate.dot");

//Get the second shape (line) of document. 
Shape shape = (Shape)template.GetChild(NodeType.Shape, 1, true);
//Get the next node of shape
Node node = shape.NextPreOrder(template);

//Get the nested table from Data.doc
Table table = (Table)data.GetChild(NodeType.Table, 3, true);
//remove empty rows of table
foreach (Row row in table.Rows)
    if (row.ToString(SaveFormat.Text).Trim().Length == 0)
NodeImporter importer = new NodeImporter(data, template, ImportFormatMode.KeepSourceFormatting);
Node newNode = importer.ImportNode(table, true);
node.ParentNode.InsertAfter(newNode, node);

template.Save(MyDir + "21.5.docx");