【问题标题】:Determine if the paragraph is a standard text or a heading确定段落是标准文本还是标题
【发布时间】:2015-10-02 19:52:45
【问题描述】:

有没有办法确定段落是标准文本还是标题?

不使用任何第三方组件,如Spire.Doc

请注意以下代码:仅当字样“标题 1”未重命名时才有效。

object thisTempStyle = p.get_Style();
Style thisparagraphStyle = thisTempStyle as Style;
string actualStyle = thisparagraphStyle.NameLocal;

if (actualStyle == "Heading 1")
...

所以,我想在不知道标题的情况下获取标题。

谢谢

【问题讨论】:

    标签: c# .net ms-word vsto word-addins


    【解决方案1】:

    您还可以检查段落的大纲级别 (https://msdn.microsoft.com/en-us/library/office/ff839401.aspx)。

    switch(thisparagraphStyle.ParagraphFormat.OutlineLevel)
    {
      case WdOutlineLevel.wdOutlineLevel1:
        // Heading 1
        break; 
      case WdOutlineLevel.wdOutlineLevelBodyText:
        // Body Paragraph
        break;
    }
    

    【讨论】:

    • 哇,太棒了!这正是我要找的!谢谢!
    猜你喜欢
    • 2012-01-29
    • 2013-04-02
    • 2013-07-26
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多