简体   繁体   English

有没有办法从Excel中的公式栏获取文本和光标位置?

[英]Is there a way to get the text and cursor position from the formula bar in Excel?

I'd like to get the current (possibly uncommitted) text out of the formula bar in Excel (from an addin in-process). 我想从Excel中的公式栏中获取当前 (可能是未提交的)文本(来自插件进程)。 All "usual" techniques don't work, like GetWindowText(...), etc. 所有“常用”技术都不起作用,如GetWindowText(...)等。

As for cursor position: GetCaretPos actually works (returns the x,y coords of the caret), but EM_CHARFROMPOS doesn't (always returns 0) so that's a dead end. 至于光标位置:GetCaretPos实际上是有效的(返回插入符号的x,y坐标),但是EM_CHARFROMPOS没有(总是返回0)所以这是一个死胡同。

Is this functionality exposed through COM or to the XLL API in any way? 此功能是以任何方式通过COM或XLL API公开的吗?

EDIT: I'd also like to point out that I think the majority of my issues come from the fact that the formula bar is (at least I'm 99% sure) NOT an edit control, which can be seen by looking at its window class. 编辑:我还想指出,我认为我的大多数问题来自公式栏(至少我99%肯定)不是编辑控件这一事实,可以通过查看它来看出窗口类。

The formula bar, and indeed most of the controls in Office are non-standard. 公式栏,实际上Office中的大多数控件都是非标准的。 Sending standard messages will not yield success. 发送标准消息不会产生成功。

I imagine the only option will be to reverse-engineer the executable code. 我想唯一的选择是对可执行代码进行反向工程。

SteveN, which version of Excel ? SteveN,哪个版本的Excel? The control will be a window. 控件将是一个窗口。 Office 2010 is 'nicer' in this respect, using more standard controls. Office 2010在这方面“更好”,使用更多标准控件。 You could use Spy to watch all the messages that get sent to that control and try mimicking those to see what you get. 您可以使用间谍来观看发送到该控件的所有消息,并尝试模仿这些消息以查看您获得的内容。 Long road though. 虽然路漫漫。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM