我计划学习Lua来满足我的桌面脚本需求。我想知道是否有可用的文档,以及标准库中是否有所有需要的东西。
发布于 2009-10-14 12:09:12
您应该查看Lua for Windows -- Windows上Lua脚本语言的“电池内含环境”
http://luaforwindows.luaforge.net/
它包括LuaCOM库,您可以从该库访问Excel对象。
请尝试查看LuaCOM文档,其中有一些Excel示例:
http://www.tecgraf.puc-rio.br/~rcerq/luacom/pub/1.3/luacom-htmldoc/
我只在非常简单的事情上使用过它。下面是一个示例,可以帮助您快速入门:
-- 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
发布于 2009-10-16 01:02:17
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)
https://stackoverflow.com/questions/1565838
复制相似问题