检查Word文档中的特定单词是否为粗体? [英] Checking if a specific word in a Word document is bold?
本文介绍了检查Word文档中的特定单词是否为粗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查Word文档中的特定单词是否为粗体?我设法找到了Bold属性,但只有在段落中至少有一个字母为粗体时,它才会在段落上返回true.我需要检查整个段落是否为粗体.
How can I check if a specific word in a Word document is bold? I've managed to find the Bold property, but it only returns true on a paragraph if at least one of the letters in the paragraph is bold. I need to be able to check if the whole paragraph is bold.
到目前为止,这是我使用Word.Interop库的代码.
Here's my code so far, using the Word.Interop library.
// Open a doc file.
var application = new Application();
var document = application.Documents.Open(path);
// Loop through all words in the document.
foreach (Paragraph paragraph in document.Paragraphs)
{
Console.WriteLine(paragraph.Range.Text + "");
Console.WriteLine();
if (paragraph.Range.Font.Bold > 0)
{
Console.WriteLine("Is bold");
Console.Read();
}
}
// Close word.
application.Quit();
推荐答案
您需要遍历每个单词或每个字母(取决于所需的精度),并检查其是否为粗体,如下所述:
you'd need to loop through each word or each letter (depending on precision needed) and check if it's bold as explained here: https://stackoverflow.com/questions/5879880/...
这篇关于检查Word文档中的特定单词是否为粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文