使用C#编辑Microsoft Word文档 [英] Edit Microsoft Word Document using C#

查看:470
本文介绍了使用C#编辑Microsoft Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void FindAndReplace(Word.Application wordApp,
            object findText, object replaceText)
        {
            object matchCase = true;
            object matchWholeWord = true;
            object matchWildCards = false;
            object matchSoundsLike = false;
            object matchAllWordForms = false;
            object forward = true;
            object format = false;
            object matchKashida = false;
            object matchDiacritics = false;
            object matchAlefHamza = false;
            object matchControl = false;
            object read_only = false;
            object visible = true;
            object replace = 2;
            object wrap = 1;

            wordApp.Selection.Find.Execute(ref findText, ref matchCase,
                ref matchWholeWord, ref matchWildCards, ref matchSoundsLike,
                ref matchAllWordForms, ref forward, ref wrap, ref format,
                ref replaceText, ref replace, ref matchKashida,
                        ref matchDiacritics,
                ref matchAlefHamza, ref matchControl);
        }



上面的代码旨在查找和替换microsoft word文档中的单词,但我发现它不适用于页眉和页脚中的单词!我怎样才能解决这个问题?


The code above aims to find and replace words in microsoft word document, but I find that it doesn't work for words in header and footer! How can I solve this problem?

推荐答案

查看这篇文章: http://www.wwco.com/~wls/blog/2010/07/03/find-and-replace-in -word-using-c-net / [ ^ ]

查看代码行67-69。它正是针对您的问题。

考虑仔细查看他们的代码。您应该检查您的代码,因为您错过了一些点,例如清除格式参数。但你也应该考虑文章的评论,因为他们指出了iterop的一些最佳实践。
Check this article: http://www.wwco.com/~wls/blog/2010/07/03/find-and-replace-in-word-using-c-net/[^]
Look at code line 67-69. It is targeting exactly your problem.
Consider looking carefully at their code. You should check your code, since you missed some points, like clearing formatting parameters. But you should also consider the comments to the article, since they point to some best practices of iterop.


这篇关于使用C#编辑Microsoft Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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