gpt4 book ai didi

C#:在Word中搜索文本并获取结果范围

转载 作者:可可西里 更新时间:2023-11-01 08:41:00 24 4
gpt4 key购买 nike

我可以通过以下方式在 Word 文件中查找文本:

Word.Range range = wordApp.ActiveDocument.Content;
Word.Find find = range.Find;
find.Text = "xxx";
find.ClearFormatting();
find.Execute(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, ref missing);

这告诉我是否找到了文本。但我需要找到的文本片段的范围。

最佳答案

你试过这个吗:

 range.Find.Execute(
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, ref missing);


while (range.Find.Found)
{
//Get selected index.
// Do as you please with range...
//Positions: range.Start... range.End
//search again
range.Find.Execute(
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, ref missing);
}

关于C#:在Word中搜索文本并获取结果范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4016960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com