c# - 如何找到我的输入文本是 BOLD Typography?

c# - How do I find my input text is BOLD Typography?

我已经在我的服务器上上传了一个 ms word 文件。上传文件后,我正在阅读该文件,我只想阅读 BOLD 个字。问题是我可以找到文件是否包含 BOLD 个单词。但我想读 BOLD 字。 以为系统说,这一段有粗体字。但我只想读那些粗体字。

我用过MS office library来读取word文件。 Microsoft.Office.Interop.Word;

以下是我检测 BOLD 个单词的代码。

    foreach (Microsoft.Office.Interop.Word.Paragraph paragraph in doc.Paragraphs)
    {
   Microsoft.Office.Interop.Word.Range parRng = paragraph.Range;
     if (parRng.Bold > 0)
        {
         //  here i can able to detect this paragraph contains bold 
         //character but unable to read those specfic bold words
        }
    }

不要遍历段落,而是使用句子。此外,您可以遍历每个单词以找出粗体文本。

using Microsoft.Office.Interop.Word;
using System;

namespace consolFindBoldWord
{
    class Program
    {
        static void Main(string[] args)
        {
            Application application = new Application();
            Document doc = application.Documents.Open("I:\word.docx");

            foreach (Range s in doc.Sentences)
            {
                foreach (Range rg in s.Words)
                {
                    if (rg.Bold == -1)
                    {

                        /*  WRITE YOUR CODE HERE IF WORD IS BOLD*/
                        Console.WriteLine("Bold : {0}", rg.Text);
                    }
                }
            }

            doc.Close();
        }
    }
}