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