使用Microsoft.Office.Interop从基于样式的段落中提取字符串数组

时间:2015-07-28 01:46:54

标签: c# .net ms-word office-interop

我有一个word文件,word文件中的每个段落都有两种样式的文本(例如 - 字体大小16后跟字体大小12)。如果我只有1个字体大小,我可以做类似下面的代码

if(wordDoc.Paragraphs[i].Range.Font.Size == 16.0f)
   string text = wordDoc.Paragraphs[i].Range.Text;

但在我的情况下,我需要为每个字体大小提取内容作为单独的字符串。 这可能使用Interop吗?

1 个答案:

答案 0 :(得分:0)

I am not sure if you need to read from a paragraph. If all you care about is capturing words formatted differently throughout the document, you might think about using Document.Words to retrieve a collection of words in the document. Each word is a Range Object.

You can use the Font.Size property for each Word while iterating through the collection to filter content according to font-size.

Let me know if that helps. Cheers!