Range.Bookmarks command very slow

@ceck Unfortunately, there are no news yet. The issue is still in analysis.

Hi Alexey, I see WORDSNET-24206 status was set to complete.
Did your team isolate the bug? In case, have you got a schedule for releasing the fixed update?
Regards,
Luca

@ceck Analysis is complete, but the issue is not yet scheduled for development.
As a temporary workaround you can try using the following code that removes the content between two nodes.

// Get start node
Node startNode = doc.Range.Bookmarks["table3"].BookmarkStart;
// Get End node
Node endNode = doc.Range.Bookmarks["table3"].BookmarkEnd;
Node curNode = startNode.NextPreOrder(doc);
while (curNode != null)
{
    if (curNode.Equals(endNode))
        break;
    // move to next node
    Node nextNode = curNode.NextPreOrder(doc);
    // Check whether current contains end node
    if (curNode.IsComposite)
    {
        if (!(curNode as CompositeNode).ChildNodes.Contains(endNode) &&
            !(curNode as CompositeNode).ChildNodes.Contains(startNode))
        {
            nextNode = curNode.NextSibling;
            curNode.Remove();
        }
    }
    else
        curNode.Remove();

    curNode = nextNode;
}

Hi Alexey,

Thanks!
I hope it will be solved before my yearly update license expires in July…
I tried the work around and it doesn’t work, the rows under the end of table3 bm are also removed beyond the end of the bm.
I saw that the condition

!(curNode as Aspose.Words.CompositeNode).ChildNodes.Contains(endNode)

is never satisfied, the bookmark end is never contained and the while loop continues until it finds another bookmark start.

Moreover I changed :

to

if (curNode.Equals(endNode))
{
    bm.Remove();
    break;
}

in order to remove bm containing the end node (it was the case of the “row” bm in my example)

Let ne know
Regards
Luca

1 Like

This is the updated project with your code included

https://www.dropbox.com/s/fkdyeu9k5pr6glj/AsposeTest_simple_v2.zip?dl=0

Luca

@ceck I have forwarded the information to our development team.

@ceck Please note that we are going to close WORDSNET-24206 ticket as “not a bug” soon. Aspose.Words policy is to mimic MS Word behavior. In this case this is assigning an empty string to Bookmark text using Word VBA.

ActiveDocument.Bookmarks("table2").Range.Text = ""

in this case MS Word simply deletes the text from the cells that fall into this Bookmark, without deleting the rows and cells themselves. Deleting the table rows and cells, however, can be performed using Aspose.Words. Above, we demonstrated you a method that allows you to do this, and as we understand it, you have successfully integrated this method into your project.
However, following the policy of simulating MS Word behavior, this mechanism cannot be a reaction to assigning an empty string to Bookmark text. Thank you for your understanding.
Please feel free to contact us if you have any questions.

@vadim.saltykov thanks for the answer but possibly there is a misunderstandement.
The problem is not about empty test, but on the fact that when I remove the bookmark containing multiple rows, those rows are not removed with the actual version while in version 18.1 all it’s was working correctly.
If you have 20 minutes time, I would propose you to show it live in a teams conference next week? In alternative I can send a very small document with just a single bookmark.
Let me know
Luca

@ceck Unfortunately, Aspose.Words behavior in version 18.1 leading to deleting rows and cells is erroneous. It is the table that represents the container for table rows, not the bookmark. Deleting a bookmark or assigning empty text to it should not result in table rows deleting. This is MS Word behavior and, unfortunately, we will have to follow it. A public API that allows one to remove an arbitrary node range set by some boundary nodes is currently under development. Before its implementation you can use the workaround specified above. We apologize for any inconvenience this may have caused.

Hi @vadim.saltykov

Thanks. I undertsand the point (or I hope so): the bookmark is inside the table so the rows are not deleted. In fact, if I create the bookmark clicking on the left of the table (and not inside the first left “cell” of the first row) and, as before, I stop selecting 2/3 rows lower out of the table on the right (both cases the bm end is there, out of the table), the rows are correctly deleted. Does this make sense to you?

Second point: as i told @alexey.noskov,

Could you help me on this point?

Luca

@ceck As for the question whether this behavior is correct or not, you can freely use VBA script I suggested above.

ActiveDocument.Bookmarks("table3").Range.Text = ""

If after executing this code for some bookmark, MS Word deletes certain table rows, then this behavior is the correct one, if not, then this behavior is not correct.

Error in line 119. If the above method is applied, the line

bm.Text = "";

is not needed and leads to an erroneous result.

The issues you have found earlier (filed as WORDSNET-24206) have been fixed in this Aspose.Words for .NET 23.6 update also available on NuGet.