none
How to map word/sentence position in OpenXML to a range in MS Word? RRS feed

  • Question

  • I'm developing the VSTO Add-In for MS Word and have faced the issue with performance. My Add-In goes through all paragraphs in the document, analyzes sentences and words and extract those which match some criteria, then I save it with the matched Range object so that I could easily navigate to it after that. The performance at this moment is very slow because the analyzer doesn't match a word or pair of words only, but also takes in account formatting (bold, italic etc.) and about 85% of CPU goes to external code which I believe goes to invoking COM components, serialization and deserialization. I believe I can re-implement the Add-In to use the OpenXML SDK, but I have not figured out if it's ever possible to match the position of word or sentence in OpenXML document to the position (Range) in the Word document so that once found I could navigate to it inside of MS Word. If it's possible could you please point me out to the right direction?
    Tuesday, August 7, 2018 10:44 AM

All replies

  • Hello Alexey Andrushkevich,

    In my opinion, Word Interop will be much easier to handle the issue about analyzes sentences and words than OpenXML. For example, OpenXML does not provide method to identify a single sentence object. Are you sure you could re-implement the Add-In using the OpenXML SDK?

    For currently, I would suggest you try to check how to improve the performance using Word Interop. What's your current issue? Will the analyzing sentences and words speed much time? If so, what's the detail logic?

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 8, 2018 1:56 AM
  • You could mark the ranges you want to work with at a later point with bookmarks or with content controls. That would be the most certain method.

    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Wednesday, August 8, 2018 4:59 PM
    Moderator
  • Thank you for your response, Terry. Yes, I'm pretty positive that I can re-implement Add-In using the OpenXML SDK. The only problem I have is that once I found the information I need to be able to navigate to the paragraph's position in MS Word. I thought the number of paragraphs in Word's object model is the same as the number of paragraphs in OpenXML SDK, but I was wrong. MS Word treats special symbols or whitespace as a separate paragraph. So what I need is to somehow match the paragraph found via OpenXML SDK to a paragraph in Word's object model. 
    Thursday, August 16, 2018 8:06 AM