1

I am trying to read values from cells of a running Excel 2007 document. I am using the WinAPI extension for Lua. I am currently running on a Windows XP computer (if that matters, but it seems the WinAPI works from XP on.

This is my Excel document:

Excel

This is my Lua code:

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

This is my Lua code output:

code output

Does anyone know how I recursively should enumerate in order to find each Cell? Or is there a better way to go about this? The text I want is the "1234". I have not done much Windows programming since I prefer Unix, but it seems like I am on the right track. I just don't know how to progress from here!

4

1 回答 1

1

我怀疑 Excel 是否为电子表格中的每个单元格都使用了一个窗口,因此试图通过导航窗口层次结构来访问单元格可能是死路一条。

如果可能,我建议将数据导出为通用文件类型,例如逗号分隔值,并让您的程序对其进行解析。

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

于 2013-06-10T22:13:27.893 回答