我如何读取luacom的xlsx文件?

我有以下代码

excel = luacom.CreateObject("Excel.Application") pcall(excel.Open, excel, "1.xlsx") if excel ~= nil then sheets = excel.Worksheets sheet1 = sheets:Item(1) for row=1, 30 do for col=1, 30 do local cellValue = sheet1.Cells(row, col).Value2 if cellValue ~= nil then --print(cellValue) end end end end 

我怎样才能修改它,以便能够读取excel文件,导致目前excelvariables没有任何workhett,似乎像加载没有顺利。

看起来你有打开函数调用错误。 尝试这个:

 local workbook = excel.Workbooks:Open("1.xlsx") 

然后使用工作簿(不是Excel)来完成其余的工作,例如:

 local sheet = workbook.Sheets(1)