使用vsto word插件功能区中的Word文档提取具有从Word文档应用的所有样式的文本

时间:2020-04-29 06:52:57

标签: c# ms-word vsto

我正在VSTO word插件中从单词中提取文本,并且也能够提取,但是我只能提取word文档中存在的任何文本,而不能提取Word文档中使用的样式。如何提取Word文档中应用的所有样式的文本。

我正在研究的代码参考。

        Document document = new Document();
        var text = Globals.ThisAddIn.Application.ActiveDocument;
        StringBuilder sb = new StringBuilder();
        //Extract Text from Word and Save to StringBuilder Instance
        foreach (Section section in text.Sections)
        {
            foreach (Paragraph paragraph in section.Range.Paragraphs)
              {
                sb.AppendLine(paragraph.Range.Text);
              }
            File.WriteAllText(@"C:\New folder\Extract.doc", sb.ToString());
            document.Close();
        }

0 个答案:

没有答案
相关问题