How to implement these statements in Aspose Word .Net

  • Move the selected content to the beginning of the current row:

Selection.HomeKey(Unit:=wdLine, Extend:=wdMove)

  • Move the selected content to the end of the current row:

Selection.EndKey(Unit:=wdLine, Extend:=wdMove)

  • Check if the selected text is empty:

ActiveWindow.Selection.Text =""

  • Remove a row:

Selection.Delete Unit:=wdCharacter, Count:=1

Hi Alex,

Thanks for your inquiry and sorry for the delayed response.

First
of all, 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 articles for more information on DOM:
https://docs.aspose.com/words/net/aspose-words-document-object-model/
https://docs.aspose.com/words/net/logical-levels-of-nodes-in-a-document/

DocumentBuilder is a powerful class that is associated with a Document and allows dynamic document building from scratch or the addition of new elements to an existing document. Pleas read following documentation links for your kind reference.

https://docs.aspose.com/words/net/document-builder-overview/
https://docs.aspose.com/words/net/navigation-with-cursor/
https://docs.aspose.com/words/net/programming-with-documents/

Moreover, you can insert specified node immediately after/before the specified reference node by using
CompositeNode.InsertAfter and CompositeNode.InsertBefore methods. Node.Remove method removes itself from the parent.

It would be great if you please share your input documents along with expected output documents which explain all of your scenarios here. We will then provide you more information about your query along with code.

Thanks for your reply!

Our purpose is to find some text or a field and then replace it. After we replace it and trim it and if it is empty then we delete this line.

For example, there is a “MASTER” field in the attached document. If we replace it with a space and then check if there is content in this line; if no content in this line we will delete this line (we are not going to delete all empty lines in the document).

Could you please let me know what would be the best approach to accomplish this?

Hi Alex,

Thanks for sharing the detail. Please note that MS Word
document is flow document and does not contain any information about
its layout into lines and pages. Therefore, technically there is no
“Page” and “Line” concept in Word document.
Aspose.Words uses our own Rendering Engine to layout documents into pages and lines. Please check using the DocumentLayoutHelper sample from the offline samples pack.
This sample demonstrates how to easily work with the layout elements of
a document and access the pages, lines, rows, spans etc.

I suggest you please read the article about ‘Find and Replace contents’ from here:
https://docs.aspose.com/words/java/find-and-replace/

Please use the same approach shared at following documentation link to find and replace text.
https://docs.aspose.com/words/java/find-and-replace/

If you want to replace Fields with some text, please check following code example. Hope this helps you.

Document doc = new Document(MyDir + "in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (Field field in doc.Range.Fields)
{
    String fieldcode = field.GetFieldCode();
    if (fieldcode.Contains("fieldName"))
    {
        builder.MoveToField(field, true);
        builder.Write(" ");
        field.Remove();
    }
}
doc.Save(MyDir + "Out.docx");

If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate as to how you want your final Word output be generated like. We will then provide you more information on this along with code.