如何使用 iterop 在 Word 文档中搜索特定字体 [英] How to search for a specific font in a Word document with iterop

查看:13
本文介绍了如何使用 iterop 在 Word 文档中搜索特定字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这样的东西:

doc.Content.Find.Font.Name = "Times New Roman";

但是当我单步执行代码时,名称属性不会改变.谢谢.

but when I step through the code the Name property doesn't change. thanks.

我正在使用 VS2010 和 MS Word 2007,我想查找所有Times New Roman"字体并将其替换为Arial".

I'm working with VS2010 and MS Word 2007 and I want to find and replace all "Times New Roman" fonts with "Arial".

会发生什么:

Word.Application wordApp = new Word.Application();
Word.Documents docs = wordApp.Documents;
doc = docs.Open(fileName, Visible: false);
doc.Content.Find.ClearFormatting();
doc.Content.Find.Replacement.ClearFormatting();

// Here the value of Find.Font.Name and Replacement.Font.Name is ""

doc.Content.Find.Font.Name = "Times New Roman";
doc.Content.Find.Replacement.Font.Name = "Arial";

// The value of Find.Font.Name and Replacement.Font.Name still "" !!!

doc.Content.Find.Execute(Format: true, Replace: Word.WdReplace.wdReplaceAll);

推荐答案

感谢您的回复,但不,您每次使用点符号时都不会得到一个新的 Find 对象.问题是您不应该在这种情况下使用 Doc.Content.Find.相反,您必须创建一个新的 Range 对象并使用它的 Find.像这样的:

Thanks for your reply, but no you don't get a new Find object each time you use dot notation. The problem is you shouldn't use Doc.Content.Find in this kind of situation. Instead you have to create a new Range object and use its Find. Something like this:

Word.Range range = doc.Range(0, doc.Content.End);

这篇关于如何使用 iterop 在 Word 文档中搜索特定字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆