How do I test if a paragraph is part of the Table Of Contents field?
Word.Application oWord = ....
doc = oWord.Documents.Open(....
foreach (Word.Paragraph p in doc.Paragraphs)
{
bool pPartOfTOC = ???
if(!pPartOfTOC){
//do stuff if not in TOC
}
}
What I'm trying to do is to parse all the paragraphs, skipping the ones that are part of the TOC. I was thinking to initially remove the TOC, but that would damage my pagination, and I need the page number also.
Any ideas?
I think you can get the tables of content from the document. Each table of content will have a Range
property and each paragraph will also have a Range
property. You should be able to check for each paragraph whether or not it is fully contained within any of the ToC ranges.
Alternatively, you might simply be able to filter by paragraph styles (e.g. TOC 1
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With