我正在使用代码在Word文档ex中找到占位符。 XXTestXX。我正在使用此代码替换文档中的文本。我无法工作的是找到占位符的开头和结尾。
查找播放器范围的最佳方法是什么?
object RangeStart = 5;
object RangeEnd = 10;
Word.Range rng = wordApp.ActiveDocument.Range(ref RangeStart, ref RangeEnd);
rng.Text = replaceText.ToString();
rng.Select();
我使用wordApp.Selection.Find.Execute来替换文本,但它有250个字符的限制。
由于
答案 0 :(得分:1)
使用此代码修复它。
Word.Range rng = aDoc.Content;
rng.Find.ClearFormatting();
rng.Find.Forward = true;
rng.Find.Text = findText.ToString();
rng.Find.Execute(ref findText, 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);
while (rng.Find.Found)
{
object RangeStart = rng.Start;
object RangeEnd = rng.End;
Word.Range rng1 = wordApp.ActiveDocument.Range(ref RangeStart, ref RangeEnd);
rng1.Text = replaceText.ToString();
rng1.Select();
rng.Find.Execute(ref findText, 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);
}