Hi, I was wondering is it possible to write to excel file based on input in program I create using AMS. If yes, can someone give me a sample code.
Writing Excel Files from AMS Input
Collapse
X
-
Hi, it's easy, first include luacom (download from http://www.indigorose.com/forums/thr...867#post156867 )
require it at startup using
PHP Code:require("luacom")
PHP Code:excel = luacom.CreateObject("Excel.Application")
excel.Visible = true
wb = excel.Workbooks:Add()
ws = wb.Worksheets(1)
cj=ws.Cells(1,2)
cj.Value2 = tostring("test")
PHP Code:local excel = luacom.CreateObject("Excel.Application")
excel.Visible = true
local wb = excel.Workbooks:Add()
local ws = wb.Worksheets(1)
for row=1,100 do
ws.Cells(row,1).Value2 = math.random()
ws.Cells(row,2).Value2 = math.random()
-- note: using ".Value2" since ".Value" fails
-- with type mismatch error. why?
end
local chart = excel.Charts:Add()
chart.ChartType = -4169 -- scatter XY
chart.HasLegend = 0
local range = ws.UsedRange
chart:SetSourceData(range, 2)
enjoy
-
Comment