【发布时间】:2010-11-10 20:41:00
【问题描述】:
我正在尝试使用 c# 和 word 自动化来更改 word 文档中的文本和图像。我已经让它在我做下面的 sn-p 之类的文本时工作得很好,但我什至不知道如何开始替换图像。
非常感谢任何帮助!
奥利弗
using Microsoft.Office.Interop.Word;
...
private static Application WordApp;
private static object missing = System.Reflection.Missing.Value;
private static object yes = true;
private static object no = false;
...
object search;
object replace;
object replaceAll =
Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
object filename = SourceFile;
object destination = DestinationFile;
Document d = WordApp.Documents.Open(
ref filename, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing);
d.Activate();
search = "OLDSTRING";
replace = "NEWSTRING";
WordApp.Selection.Find.Execute(
ref search, ref yes, ref yes, ref no, ref no, ref no, ref yes,
ref missing, ref missing, ref replace, ref replaceAll,
ref missing, ref yes, ref missing, ref missing);
【问题讨论】:
-
很好奇你想做出什么样的解决方案。这是您在 Word 加载项中公开的功能,还是来自外部应用程序的某种批处理自动化?如果是外部的,我宁愿在 2007 年通过 OpenXML SDK 覆盖 WordML,或者在 2003 年使用 xml 来代替。做起来更快更容易。
-
只是一个建议。使用 VB。它将使您在 COM 自动化领域的生活更轻松。至于替换图像,您可以查看“范围”,并且可能能够遍历其中的文本和对象以查找图像对象类型。
-
@roygbiv:+1。 VB 更容易实现 COM 自动化
-
@oktavakol:你想用什么替换图片?
标签: c# image automation ms-word replace