微软办公室互操作词

微软办公室互操作词

本文介绍了微软办公室互操作词:如何知道一个段落是否是一个标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 C# 编写一个 VSTO 插件来解析 Office Word 文档.

I'm writing a VSTO add-ins in C# that parses an Office Word document.

我必须检查文档的每个图形是否都有标题标签.我设法知道一个段落何时包含一个图:

I have to check if each figure of the document has a caption label.I managed to know when a paragraph contains a Figure:

var activeDoc = Globals.ThisAddIn.Application.ActiveDocument;


for (int i = 0; i < activeDoc.Paragraphs.Count; i++)
{
    Paragraph par = activeDoc.Paragraphs[i + 1];

    if (par.Range.InlineShapes.Count == 1)
    {
        // the paragraph has an image
    }
}

但我看不到任何方法可以知道该段落是标题还是简单文本.

but I don't see any ways to know if the paragraph is a caption or simple text.

我尝试使用 CaptionLabels 但它返回标题的类型 [图、表格、公式],而不是我文档中的所有标题.

I tried to use CaptionLabels but it returns the types of the captions [Figure, Table, Equation] and not all the captions in my documents.

推荐答案

我进行了一个快速测试,作为标题的段落应用了一个内置样式,称为标题"(par.Style.NameLocal) 如果该名称是始终使用标题"(或者您将其作为参数提供),然后您就可以将非标题段落与​​标题区分开来.

I ran a quick test and the paragraph that is a caption has a builtin style applied that's called 'Caption' (par.Style.NameLocal) If that name is always 'Caption' (or you feed it as a parameter) then you can distinguish non-caption paragraphs from captions.

提示:编写一些测试代码并放置一个断点来检查对象并找出它们的独特之处.在这种情况下,段落/范围样式是标题".这是最有效的方式imo.

As a tip: write a little test code and put a breakpoint to examine the objects and find what makes them unique. In this case the paragraph/range style is 'Caption'. This is the most efficient way imo.

这篇关于微软办公室互操作词:如何知道一个段落是否是一个标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:02