Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Lua处理excel_Excel_Lua - Fatal编程技术网

使用Lua处理excel

使用Lua处理excel,excel,lua,Excel,Lua,我计划学习Lua以满足我的桌面脚本需求。我想知道是否有任何可用的文档,以及标准库中是否有所需的所有内容。您应该查看Lua for Windows-Windows上Lua脚本语言的“含电池的环境” 它包括LuaCOM库,您可以从中访问Excel COM对象 尝试查看LuaCOM文档,其中有一些Excel示例: 我只在非常简单的事情上使用过这个。以下是一个让您开始学习的示例: -- test.lua require('luacom') excel = luacom.CreateObject("Exc

我计划学习Lua以满足我的桌面脚本需求。我想知道是否有任何可用的文档,以及标准库中是否有所需的所有内容。

您应该查看Lua for Windows-Windows上Lua脚本语言的“含电池的环境”

它包括LuaCOM库,您可以从中访问Excel COM对象

尝试查看LuaCOM文档,其中有一些Excel示例:

我只在非常简单的事情上使用过这个。以下是一个让您开始学习的示例:

-- test.lua
require('luacom')
excel = luacom.CreateObject("Excel.Application")
excel.Visible = true
wb = excel.Workbooks:Add()
ws = wb.Worksheets(1)

for i=1, 20 do
    ws.Cells(i,1).Value2 = i
end

您应该查看Lua for Windows,这是Windows上Lua脚本语言的“含电池环境”

它包括LuaCOM库,您可以从中访问Excel COM对象

尝试查看LuaCOM文档,其中有一些Excel示例:

我只在非常简单的事情上使用过这个。以下是一个让您开始学习的示例:

-- test.lua
require('luacom')
excel = luacom.CreateObject("Excel.Application")
excel.Visible = true
wb = excel.Workbooks:Add()
ws = wb.Worksheets(1)

for i=1, 20 do
    ws.Cells(i,1).Value2 = i
end

lua使用excel的更复杂代码示例:

require "luacom"

excel = luacom.CreateObject("Excel.Application")

local book  = excel.Workbooks:Add()
local sheet = book.Worksheets(1)

excel.Visible = true

for row=1, 30 do
  for col=1, 30 do
    sheet.Cells(row, col).Value2 = math.floor(math.random() * 100)
  end
end


local range = sheet:Range("A1")

for row=1, 30 do
  for col=1, 30 do
    local v = sheet.Cells(row, col).Value2

    if v > 50 then
        local cell = range:Offset(row-1, col-1)

        cell:Select()
        excel.Selection.Interior.Color = 65535
    end
  end
end

excel.DisplayAlerts = false
excel:Quit()
excel = nil 
另一个例子是,可以添加一个图表

require "luacom"

excel = luacom.CreateObject("Excel.Application")

local book  = excel.Workbooks:Add()
local sheet = book.Worksheets(1)

excel.Visible = true

for row=1, 30 do
  sheet.Cells(row, 1).Value2 = math.floor(math.random() * 100)
end

local chart = excel.Charts:Add()
chart.ChartType = 4 — xlLine

local range = sheet:Range("A1:A30")
chart:SetSourceData(range) 

lua使用excel的更复杂代码示例:

require "luacom"

excel = luacom.CreateObject("Excel.Application")

local book  = excel.Workbooks:Add()
local sheet = book.Worksheets(1)

excel.Visible = true

for row=1, 30 do
  for col=1, 30 do
    sheet.Cells(row, col).Value2 = math.floor(math.random() * 100)
  end
end


local range = sheet:Range("A1")

for row=1, 30 do
  for col=1, 30 do
    local v = sheet.Cells(row, col).Value2

    if v > 50 then
        local cell = range:Offset(row-1, col-1)

        cell:Select()
        excel.Selection.Interior.Color = 65535
    end
  end
end

excel.DisplayAlerts = false
excel:Quit()
excel = nil 
另一个例子是,可以添加一个图表

require "luacom"

excel = luacom.CreateObject("Excel.Application")

local book  = excel.Workbooks:Add()
local sheet = book.Worksheets(1)

excel.Visible = true

for row=1, 30 do
  sheet.Cells(row, 1).Value2 = math.floor(math.random() * 100)
end

local chart = excel.Charts:Add()
chart.ChartType = 4 — xlLine

local range = sheet:Range("A1:A30")
chart:SetSourceData(range) 

感谢uroc的快速回复。如果可能,请告诉我任何初学者教程或至少一些通过Lua使用COM编程的示例代码:感谢uroc的快速回复。如果可能,请告诉我任何初学者教程或至少一些通过Lua使用COM编程的示例代码:快速建议:如果您使用101 010小按钮将代码片段格式化,那么代码片段看起来会更好。快速建议:如果您使用101 010小按钮将代码片段格式化,那么代码片段看起来会更好。