如何从MS-Word获取坐标?

时间:2015-08-28 10:24:57

标签: c# ms-word office-interop

例如,我有一个名为 first.doc 的文档,其中包含两个 Hello World 的单词。我想获得 Hello World 的坐标。有没有办法获得这些坐标?

1 个答案:

答案 0 :(得分:1)

Range.FindWindow.GetPoint可用于解决此问题:

Application application = new Application();
Document wordDoc = application.Documents.Open(@"C:\first.doc");

Range range = application.ActiveDocument.Content;
range.Find.Execute("hello world");
int left, top, width, height;
application.ActiveWindow.GetPoint(out left, out top, out width, out height, range);