如何检查Word段落是否是目录的一部分?
如何测试段落是否是目录字段的一部分?
Word.Application oWord = ....
doc = oWord.Documents.Open(....
foreach (Word.Paragraph p in doc.Paragraphs)
{
bool pPartOfTOC = ???
if(!pPartOfTOC){
//do stuff if not in TOC
}
}
我想做的是解析所有段落,跳过目录中的段落。我想最初删除目录,但这会损坏我的分页,而且我还需要页码。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你可以从文档中获取目录。每个目录都有一个
Range
属性,每个段落也将有一个Range
属性。您应该能够检查每个段落是否完全包含在任何目录范围内。或者,您可以简单地按段落样式进行过滤(例如
TOC 1
)。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 aRange
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
).