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