使用Word.Interop与åäö发生错误:查找替换c#.Net

时间:2015-07-31 09:28:26

标签: c# office-interop

我有一个word文档,我将其传递给一个函数,该函数超级编写两个“£”之间的所有内容。问题是,如果我没有在我的计算机上启用英语设置,将显示错误(瑞典语)抱怨匹配。我想这与这个特定的行doc.Find.Text = "£([A-Z]{1,5})£";有关,因为该文件还包含字母å,ä和ö。然而,无论我尝试什么,我都无法让它工作,我真的被卡住了。我不是Interop专家,所以如果有人能帮助我,我会非常感激!

public void SuperScript(Word.Range doc)
    {
        doc.Find.Replacement.Font.Superscript = 1;
        doc.Find.MatchWildcards = true;
        doc.Find.Text = "£([0-9]{1,5})£";
        doc.Find.Replacement.Text = @"\1";

        doc.Find.Execute(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Word.WdReplace.wdReplaceAll, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

        doc.Find.Text = "£([A-Z]{1,5})£";
        doc.Find.Replacement.Text = @"\1";

        doc.Find.Execute(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Word.WdReplace.wdReplaceAll, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

        doc.Find.Text = "£([a-z]{1,5})£";
        doc.Find.Replacement.Text = @"\1";

        doc.Find.Execute(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Word.WdReplace.wdReplaceAll, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
    }

1 个答案:

答案 0 :(得分:0)

我只是在猜...希望这是你的答案...... 您可以执行"£(\w[^0-9]{1,5})£""£(\D{1,5})£之类的操作,不包括数字。如果您不关心返回的字符类型,则可以执行"£(.{1,5})£"