This time I want to ask whether you can provide me with some sample code regarding the following requirement.
Suppose you have a bookmark that covers a region in a document. This region can be some columns, rows or multiple cells in a table. It can also be cover multiple paragraphs or some other fancy part of the document. All the content covered by the bookmark should be deleted.
Within Microsoft Word I do the following the achieve this:
1. Use Control+G to navigate to the requested bookmark. This will select all the content covered by it.
2. Press "Delete" to delete all the content selected by the previous step.
Here is the marco that Microsoft Word records ("S3" is the name of the bookmark in my example):
- Code: Select all
Sub Makro1()
Selection.GoTo What:=wdGoToBookmark, Name:="S3"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Cut
End Sub
How can this be achieved using the Spire.Doc for Java-API, please?
I've already tried the following:
- Code: Select all
BookmarksNavigator navigator = new BookmarksNavigator(document);
navigator.moveToBookmark("S3");
navigator.deleteBookmarkContent(false);
But this does not work, if the bookmark covers a table row or a table column.
If it covers a table row, I receive the following exception:
- Code: Select all
java.lang.UnsupportedOperationException: Not supported deleting content between bookmarks in different paragraphs
at com.spire.doc.documents.BookmarksNavigator.spr═┩—(Unknown Source)
at com.spire.doc.documents.BookmarksNavigator.deleteBookmarkContent(Unknown Source)
If it covers a table column, I receive the following exception:
- Code: Select all
com.spire.doc.packages.sprztx: Specified argument was out of the range of valid values.
Parameter name: Parameter name: index
com.spire.doc.packages.spryor.spr†©(List.java:489)
com.spire.doc.packages.sprgpga.spr▢§(Unknown Source)
com.spire.doc.collections.DocumentObjectCollection.get_Item(Unknown Source)
com.spire.doc.collections.DocumentObjectCollection.get(Unknown Source)
com.spire.doc.collections.BodyRegionCollection.spr▆(Unknown Source)
com.spire.doc.collections.BodyRegionCollection.get(Unknown Source)
com.spire.doc.documents.BookmarksNavigator.spr▤┩—(Unknown Source)
com.spire.doc.documents.BookmarksNavigator.spr═┩—(Unknown Source)
com.spire.doc.documents.BookmarksNavigator.deleteBookmarkContent(Unknown Source)
Kind regards,
Marcus