Figure 16   Generate Chart Using Excel.asp


 <%
 'This ASP script uses Office 2000 to generate a chart via Excel.
 'Once the chart is generated the browser is redirected to the
 'generated page.
 'Written for MIND by E. Bruce Shankle III, CodeMarine, Inc.
 
 
 'Variables
 dim xl
 dim fso
 dim filename
 
 'Create the objects we need
 Set xl = server.createobject("Excel.Application")
 Set fso = server.createobject("Scripting.FileSystemObject")
 
 'Delete the previous chart if it exists
 filename = "f:\codemarine\excel\charttest.htm"
 If fso.FileExists(filename) Then
     fso.DeleteFile filename, True
 End If
 
 'Create a new workbook
 xl.Workbooks.Add
 
 'Put in some sample data
 xl.Range("A1").Value = "Excel Chart Test"
 xl.Range("A2").Value = "Simple Chart"
 xl.Range("A3").Value = "1"
 xl.Range("A4").Value = "2"
 xl.Range("A5").Value = "3"
 xl.Range("A6").Value = "4"
 xl.Range("A7").Value = "5"
 
 'Add a new chart
 xl.Charts.Add
 xl.ActiveChart.ChartType = xlColumnClustered
 
 'Set the data source of the chart
 xl.ActiveChart.SetSourceData xl.Sheets("Sheet1").Range("A2:A7"), xlColumns
 
 'Save the chart in HTML format
 xl.ActiveChart.SaveAs filename, xlHtml
 
 'Close the workbook
 xl.ActiveWorkbook.Close
 
 'Shut down excel
 xl.Quit
 
 'Redirect the browser to the page that has a reference to the chart.
 response.redirect "charttest.htm"
 
 %>