如何更改doc文件的特定单词的字体 [英] how to change font of a specific word of a doc file
本文介绍了如何更改doc文件的特定单词的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含许多段落的单词文件,其中一些包含一个单词vs,我需要强调一点,我正在使用这段代码,但是无法得到我想要的。
请帮帮我......
<前lang =c#> foreach (word.Paragraph para in doc.Paragraphs)
{
if ( para.Range.Text.Contains( vs))
{
foreach (word.Range words in para.Range.Words)
{
if (wordss.Text.Trim()。ToLower()== vs)
{
words.Font.Bold = 1 ;
}
}
}
}
解决方案
反而迭代通过收集单词,使用替换
方法。
看看这里:
如何:以编程方式搜索和替换文档中的文本 [ ^ ]
如何:以编程方式格式化文档中的文本 [ ^ ]
hi,
将在代码片段下方为您工作?更多deatils你chech文章 - [删除垃圾邮件链接]
// 创建文档
文档文档= 新文档();
document.LoadFromFile( @ 示例文件);
TextSelection [] text = document.FindAllString( vs,< span class =code-keyword> false , true );
foreach (TextSelection seletion in text)
{
seletion。 GetAsOneRange()。CharacterFormat.HighlightColor = Color.Yellow;
}
document.SaveToFile( FindHighlight.docx ,FileFormat.Docx);
System.Diagnostics.Process.Start( FindHighlight.docx);
i have a word file which contains many Paragraphs and some of them contains a word "vs", i need to highlight that, for which i'm using this code, but could not get what i wanted.
Please help me in this...
foreach (word.Paragraph para in doc.Paragraphs)
{
if (para.Range.Text.Contains("vs"))
{
foreach (word.Range words in para.Range.Words)
{
if (wordss.Text.Trim().ToLower() == "vs")
{
words.Font.Bold = 1;
}
}
}
}
解决方案
Instead iterating through the collection of words, useReplace
method.
Have a look here:
How to: Programmatically Search for and Replace Text in Documents[^]
How to: Programmatically Format Text in Documents[^]
hi,
will below code snippet work for you? More deatils you chech the article- [Spam link removed]
//Create Document Document document = new Document(); document.LoadFromFile(@"sample file"); TextSelection[] text = document.FindAllString("vs", false, true); foreach (TextSelection seletion in text) { seletion.GetAsOneRange().CharacterFormat.HighlightColor = Color.Yellow; } document.SaveToFile("FindHighlight.docx", FileFormat.Docx); System.Diagnostics.Process.Start("FindHighlight.docx");
这篇关于如何更改doc文件的特定单词的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文