Site Tools

Automating Excel From RhinoScript

Developer: RhinoScript
Summary: Illustrates RhinoScript code that launches and automates Microsoft Excel


The following example RhinoScript code demonstrates how to launch Microsoft Excel and populate a worksheet with data.

 Sub TextExcel()
   ' Launch Excel
   Dim app
   Set app = CreateObject("Excel.Application")
   ' Make it visible
   app.Visible = True
   ' Add a new workbook
   Dim wb
   Set wb = app.workbooks.add
   ' Fill array of values first...
   Dim arr(19,9) ' Note: VBScript is zero-based
   For i = 1 To 20
     For j = 1 To 10
       arr(i-1,j-1) = i*j
   ' Declare a range object to hold our data
   Dim rng
   Set rng = wb.Activesheet.Range("A1").Resize(20,10)
   ' Now assign them all in one shot...
   rng.value = arr
   ' Add a new chart based on the data
   wb.ActiveChart.ChartType = 70 'xl3dPieExploded
   wb.ActiveChart.SetSourceData rng, 2 ' xlColumns
   wb.ActiveChart.Location 2, "Sheet1" 'xlLocationAsObject

   ' Rotate it around...
   For i = 1 To 360 Step 30
     wb.activechart.rotation = i
   ' Give the user control of Excel
   app.UserControl = True
 End Sub

developer/scriptsamples/excel.txt ยท Last modified: 2015/12/04 by sandy