A
Alex
Hello,
I've run into a problem in my C# add-in for Word.
One of the operations that the add-in has to do is going over all bookmarks in a document and removing the bookmarks and its content if certain conditions are true.
Originally, I tried the following:
bookmark.Range.Text = "";
Unfortunately, it did not work correctly in all cases (for example, if the bookmark spanned table cells).
So I used the following:
Microsoft.Office.Interop.Word.Range range = bookmark.Range;
bookmark.Delete();
range.Delete(ref missing, ref missing);
when "missing" was initialized thus:
object missing = System.Reflection.Type.Missing;
That works correctly but, according to the profiler, is 4-5 times slower!
Since this operation is performed in a tight loop, on a document with a lot of bookmarks that need to be deleted, this slowdown is VERY noticeable.
The breakdown of the timing between the 3 lines is roughly:
Microsoft.Office.Interop.Word.Range range = bookmark.Range; // 3.6%
bookmark.Delete(); // 13.8%
range.Delete(ref missing, ref missing); // 82.6%
So the culprit is the range.Delete() operation.
I really need to speed this up!
Any help is appreciated.
Thanks,
Alex.
I've run into a problem in my C# add-in for Word.
One of the operations that the add-in has to do is going over all bookmarks in a document and removing the bookmarks and its content if certain conditions are true.
Originally, I tried the following:
bookmark.Range.Text = "";
Unfortunately, it did not work correctly in all cases (for example, if the bookmark spanned table cells).
So I used the following:
Microsoft.Office.Interop.Word.Range range = bookmark.Range;
bookmark.Delete();
range.Delete(ref missing, ref missing);
when "missing" was initialized thus:
object missing = System.Reflection.Type.Missing;
That works correctly but, according to the profiler, is 4-5 times slower!
Since this operation is performed in a tight loop, on a document with a lot of bookmarks that need to be deleted, this slowdown is VERY noticeable.
The breakdown of the timing between the 3 lines is roughly:
Microsoft.Office.Interop.Word.Range range = bookmark.Range; // 3.6%
bookmark.Delete(); // 13.8%
range.Delete(ref missing, ref missing); // 82.6%
So the culprit is the range.Delete() operation.
I really need to speed this up!
Any help is appreciated.
Thanks,
Alex.