Free Support Forum - aspose.com

Backspace command

Hi, I have a bookmark on my page that if the source does not exist, the selection needs to be backspaced (as in MS word). Can I do this in aspose.word?

This is the code that is used for the MSWord COM object for example:

if (bookmark.Name.Contains(“AddressLine2”) && (data == string.Empty))
{
bookmark.Range.Select();
bookmark.Range.Text = data;
wordApp.Selection.TypeBackspace();
}
else
{
bookmark.Range.Text = data;
}

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I think that you can just set bookmark text as empty string. For example see the following code.

doc.Range.Bookmarks["myBookamrk"].Text = string.Empty;

Hope this helps. Also you can attach your document here for testing. I will investigate it and try to help you.

Best regards.

Sorry, what I am trying to do is as follows:

Original document with bookmarks:
Line1
Line2
Line3

What I want after the mailmerging:
Line1
Line3

The line2 is removed completely, not like
Line1

Line3

I need to move the bookmarks up.

I tried using Aspose.Editor but I cannot see how the both can interface with each other. I hope this helps my explanation.

I’ve also uploaded a file that I’m trying to use it with.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I think that you can try removing paragraph. For example you can try using the following code.

//Open document

Document doc = new Document(@"Test115\in.doc");

//Get bookmark

Bookmark myBookmark = doc.Range.Bookmarks["myBookmark"];

//Remove parent paragraph

myBookmark.BookmarkStart.GetAncestor(typeof(Paragraph)).Remove();

//Save output document

doc.Save(@"Test115\out.doc");

I hope this could help you.

Best regards.

Hi

Many thanks, that worked well.

Regards,
Jimmy