Lua WinAPI – 从Microsoft Excel读取单元格

我正在尝试从正在运行的Excel 2007文档的单元格中读取值。 我正在使用Lua的WinAPI扩展 。 我目前正在Windows XP电脑上运行(如果有的话,但似乎WinAPI从XP工作。

这是我的Excel文档:

高强

这是我的Lua代码:

require 'winapi' w = winapi.find_window_match('Book1') -- Specify the name of the window w:show() -- Set the visability w:set_foreground() -- Bring this window to the foreground handle = w:get_handle() -- Get window handle t = {} -- Create a table w:enum_children(function(w) table.insert(t,w) end) -- Enumerate all children for k,v in pairs(t) do -- Print out all pairs in the table print("",k,"=",v) end 

这是我的Lua代码输出:

代码输出

有谁知道我如何recursion应枚举为了find每个细胞? 还是有更好的方法去做这件事? 我想要的文字是“1234”。 因为我更喜欢Unix,所以我没有做太多的Windows编程,但是看起来我正走在正确的道路上。 我只是不知道如何从这里进步!

我怀疑Excel使用电子表格中的每个单元格的窗口,所以试图通过浏览窗口层次结构来到达单元格可能是死路一条。

如果可能的话,我build议将数据导出到一个通用的文件types,如逗号分隔值,并让你的程序parsing。

或者,您可以阅读有关UI自动化的信息 ,即屏幕阅读器可以如何访问Windows应用程序UI中的数据。 我从来没有这样做,但看起来可能是很多工作。 尽pipe如此,我相信这是尝试通过用户界面从Windows应用程序中获取数据的最强大的支持方法。