Automating Excel From RhinoScript
Developer: RhinoScript
Summary: Illustrates RhinoScript code that launches and automates Microsoft Excel.
Example
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 Next Next ' 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.Charts.Add 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 Next ' Give the user control of Excel app.UserControl = True End Sub