Hauknu

I need to retrieve a list with all heading style paragraphs in a document. I first looped through every paragraph in the document and tested on "OutlineLevel", but as the document is rather large, this proved to be way too slow.

The "Table of Contents" is being build very quick, so obviously there are better ways than mine out there. Would greatly apprecciate it if someone could help me out!



Re: Visual Studio Tools for Office How do I retrieve a list of all headings in a document?

Johan Nordberg

This is something that's really missing in Word. As a web developer I really miss having a good DOM for the Word document where headings are marked up with good semantics. Even if you use the WordML XMLDOM it's not that easy to select just the headings if you don't know the names of heading styles.

What I did when I needed this I used the Search function to search for text with a specific styles. That's alot faster than looping thru all paragraphs.

// Johan






Re: Visual Studio Tools for Office How do I retrieve a list of all headings in a document?

Cindy Meister

I'm afraid your question is off-topic in this forum, targeted at the VSTO technology. General questions about Office object models and the interop should be asked in an appropriate newsgroup, as listed in the Please Read First message at the top of this forum. Such questions are appropriate here only when they have to do with how the Tools interact with the Office application. It's also very important that you mention the version of the application involved, otherwise no one can know what options are available to you. No one wants to waste their time writing up answers that turn out to be inapplicable. And I'm sure you don't want to waste yours trying to implement something not supported by your configuration.

Office object models tend to be slow, especially if automated from outside the application, itself. It sounds like you've tried the only methods available in the object model. That would leave processing the file contents directly (parsing the XML, for example, if we're talking about Word 2003 or 2007) as your other option.