【发布时间】:2016-12-17 04:43:02
【问题描述】:
我有一个模板 .docx 文件,我必须在其中替换占位符。我使用c# word interop find and replace everything 中的代码替换了我的word 文件中的名称。效果很好。
object fileName = GetFilePath();
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = true };
Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(fileName, ReadOnly: false, Visible: true);
aDoc.Activate();
FindAndReplace(wordApp, "firstname", "Max");
aDoc.Save();
这个实现确实打开了 word 文件。 我的问题是,是否有任何方法可以在不打开文件的情况下替换文本?
【问题讨论】:
-
当你说“不打开文件”时,你的意思是根本不打开文件,还是只是不想让用户看到word文件已经打开? (即它不应该出现在任务栏等中)
-
@Bassie 我不希望用户看到 word 文件已被打开,因为 Andrejs Mivreniks 解释说没有打开它就没有办法。
-
我添加了我自己的答案是你想要什么?
-
@Bassie 我没有时间检查你的答案。我会检查,如果正确,会尽快接受。新年快乐!