【问题标题】:c# Interop.Word Find.Execute inside of a textbox in word docc# Interop.Word Find.Execute 在 word doc 中的文本框内
【发布时间】:2019-09-17 11:40:27
【问题描述】:

我正在使用 FindAndReplace 之类的内置函数将 Word 文档中的某些文本替换为新文本。但是当想要的文本在文本框内时,函数似乎找不到它。

我的代码:

object matchCase = true;
object matchWholeWord = true;
object matchWildCards = false;
object matchSoundLike = false;
object nmatchAllforms = false;
object forward = true;
object format = true;
object matchKashida = false;
object matchDiactitics = false;
object matchAlefHamza = false;
object matchControl = false;
object read_only = false;
object visible = true;
object replace = 2;
object wrap = 1;

var range = myWordDoc.Range();

//Finds the parameter, then replaces
range.Find.Execute("replaceable",
ref matchCase, ref matchWholeWord,
ref matchWildCards, ref matchSoundLike,
ref nmatchAllforms, ref forward,
ref wrap, ref format, "value",
ref replace, ref matchKashida,
ref matchDiactitics, ref matchAlefHamza,
ref matchControl);

有一个选项可以遍历文件中的所有文本框并在内部文本上调用函数? (实际上并没有用这样的新文本替换里面的整个文本:)

shape.TextFrame.TextRange.Text = resultingText;

提前谢谢你!

【问题讨论】:

    标签: c# ms-word


    【解决方案1】:

    shape.TextFrame.TextRange返回一个Range对象,所以在文档中循环Shapes,测试类型是否为文本框,然后

    var rngTextBox = shape.TextFrame.TextRange;
    
    //Finds the parameter, then replaces
    rngTextBox.Find.Execute("replaceable", //etc.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多