简体   繁体   English

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

[英]How to get Style of a document (word) with C#

I have a document (MS Word) and I applied the "Line (Distincive)" style to it.我有一个文档 (MS Word),我对其应用了“线条(独特)”样式。 Now I want to get the name of Style in this document (Line Distincive) with using C#.现在我想使用 C# 获取此文档中的样式名称(Line Distinctive)。 I don't know how to solve this problem.我不知道如何解决这个问题。 This is my code.这是我的代码。

在此处输入图片说明

    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());
}

您需要从ParagraphProperties获取样式,如下所示:

var style = paragraph.ParagraphProperties.ParagraphStyleId.Val.Value;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM