Writing Excel Files from AMS Input

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • hus2020
    Forum Member
    • Jul 2008
    • 17

    Writing Excel Files from AMS Input

    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.
  • LucasTheDuck
    No longer a forum member
    • Oct 2009
    • 123

    #2
    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"
    Then you can create excel documents fastly, some samples:

    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"
    This shuld create a worksheet with test at row 1 col 2

    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()
         -- 
    noteusing ".Value2" since ".Value" fails
         
    -- with type mismatch errorwhy?
      
    end
      local chart 
    excel.Charts:Add()
      
    chart.ChartType = -4169  -- scatter XY
      chart
    .HasLegend 0
      local range 
    ws.UsedRange
      chart
    :SetSourceData(range2
    This creates a sheet (2) with random data, and other sheet (1) with chart

    enjoy

    Comment

    Working...
    X