日期:2013-04-02  浏览次数:20910 次

现在我们针对EXCEL举另外一个例子,大家都询问如何用ASP建立图表的问题,以下就是解决方案<BR><BR>First we set the type of script<BR>首先设定脚本类型<BR><%@ LANGUAGE="VBSCRIPT" %><BR><BR>Make the object, and set the object to an Excelsheet<BR>建立Excelsheet对象<BR><BR>Dim MyExcelChart<BR>Set MyExcelChart = CreateObject("Excel.Sheet")<BR><BR>' show or dont show excel to user, TRUE or FALSE<BR>是否让用户看到EXCEL表格,真或假<BR>MyExcelChart.Application.Visible = True<BR><BR>' populate the cells<BR>添EXCEL表格<BR>MyExcelChart.ActiveSheet.Range("B2:k2").Value = Array("Week1", "Week2", "Week3", "Week4", "Week5", "Week6", "Week7", "Week8", "Week9", "Week10")<BR>MyExcelChart.ActiveSheet.Range("B3:k3").Value = Array("67", "87", "5", "9", "7", "45", "45", "54", "54", "10")<BR>MyExcelChart.ActiveSheet.Range("B4:k4").Value = Array("10", "10", "8", "27", "33", "37", "50", "54", "10", "10")<BR>MyExcelChart.ActiveSheet.Range("B5:k5").Value = Array("23", "3", "86", "64", "60", "18", "5", "1", "36", "80")<BR>MyExcelChart.ActiveSheet.Cells(3,1).Value="Internet Explorer"<BR>MyExcelChart.ActiveSheet.Cells(4,1).Value="Netscape"<BR>MyExcelChart.ActiveSheet.Cells(5,1).Value="Other"<BR><BR>' Select the contents that need to be in the chart<BR>在EXCEL表中选择要在图表(CHART)中显示的数据<BR>MyExcelChart.ActiveSheet.Range("b2:k5").Select<BR><BR>' Add the chart<BR>加载图表(CHART)<BR>MyExcelChart.Charts.Add<BR>' Format the chart, set type of chart, shape of the bars, show title, get the data for the chart, show datatable, show legend<BR>初始化图表(CHART),设定图表类型,棒图的形状,要显示的标题,取得要作图的数据,显示数据表,显示图表<BR>MyExcelChart.activechart.ChartType = 97<BR>MyExcelChart.activechart.BarShape =3<BR>MyExcelChart.activechart.HasTitle = True<BR>MyExcelChart.activechart.ChartTitle.Text = "Visitors log for each week shown in browsers percentage"<BR>MyExcelChart.activechart.SetSourceData MyExcelChart.Sheets("Sheet1").Range("A1:k5"),1<BR>MyExcelChart.activechart.Location 1<BR>MyExcelChart.activechart.HasDataTable = True<BR>MyExcelChart.activechart.DataTable.ShowLegendKey = True<BR><BR>' Save the the excelsheet to excelface<BR>存入EXCEL表<BR>MyExcelChart.SaveAs "c:\chart.xls"<BR>%><BR><BR>Now lets complete the HTML tags.<BR>下面是HTML代码<BR><BR><HTML><BR><HEAD><BR><TITLE>MyExcelChart</TITLE><BR></HEAD><BR><BODY><BR></BODY><BR></HTML><BR><BR>This completes yer ASP page, look below for the complete code of myexcelchart.asp<BR>下面是源程序myexcelchart.asp的完整代码<BR><BR><%@ LANGUAGE="VBSCRIPT" %><BR><%<BR>Set MyExcelChart = CreateObject("Excel.Sheet")<BR><BR>MyExcelChart.Application.Visible = True<BR><BR>MyExcelChart.ActiveSheet.Range("B2:k2").Value = Array("Week1", "Week2", "Week3", "Week4", "Week5", "Week6", "Week7", "Week8", "Week9", "Week10")<BR>MyExcelChart.ActiveSheet.Range("B3:k3").Value = Array("67", "87", "5", "9", "7", "45", "45", "54", "54&quo