如何使用C#获取文档(单词)的样式

问题描述 投票:0回答:1

我有一个文档(MS Word),并且对它应用了“线条(独特)”样式。现在,我想使用C#获取此文档中的Style名称(Line Distincive)。我不知道如何解决这个问题。这是我的代码。

enter image description here

    void ApplyStyleDocument()
    {
        object w;
        Microsoft.Office.Interop.Word.Document _activeDoc;
        try
        {
             w = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
        }
        catch (Exception ex)
        {
            Type type = Type.GetTypeFromProgID("Word.Application");
            w = System.Activator.CreateInstance(type);
        }
       Microsoft.Office.Interop.Word.Application oWord = (Microsoft.Office.Interop.Word.Application)w;
       _activeDoc = oWord.ActiveDocument;
       MessageBox.Show(_activeDoc.Styles.GetType().Name.ToString());
}
c# ms-word interop
1个回答
0
投票

您需要像这样从ParagraphProperties中获取样式:

var style = paragraph.ParagraphProperties.ParagraphStyleId.Val.Value;
© www.soinside.com 2019 - 2024. All rights reserved.