现在我们针对excel举另外一个例子,大家都询问如何用asp建立图表的问题,以下就是解决方案
first we set the type of script
首先设定脚本类型
<%@ language="vbscript" %>
make the object, and set the object to an excelsheet
建立excelsheet对象
dim myexcelchart
set myexcelchart = createobject("excel.sheet")
show or dont show excel to user, true or false
是否让用户看到excel表格,真或假
myexcelchart.application.visible = true
populate the cells
添excel表格
myexcelchart.activesheet.range("b2:k2").value = array("week1", "week2", "week3", "week4", "week5", "week6", "week7", "week8", "week9", "week10")
myexcelchart.activesheet.range("b3:k3").value = array("67", "87", "5", "9", "7", "45", "45", "54", "54", "10")
myexcelchart.activesheet.range("b4:k4").value = array("10", "10", "8", "27", "33", "37", "50", "54", "10", "10")
myexcelchart.activesheet.range("b5:k5").value = array("23", "3", "86", "64", "60", "18", "5", "1", "36", "80")
myexcelchart.activesheet.cells(3,1).value="internet explorer"
myexcelchart.activesheet.cells(4,1).value="netscape"
myexcelchart.activesheet.cells(5,1).value="other"
select the contents that need to be in the chart
在excel表中选择要在图表(chart)中显示的数据
myexcelchart.activesheet.range("b2:k5").select
add the chart
加载图表(chart)
myexcelchart.charts.add
format the chart, set type of chart, shape of the bars, show title, get the data for the chart, show datatable, show legend
初始化图表(chart),设定图表类型,棒图的形状,要显示的标题,取得要作图的数据,显示数据表,显示图表
myexcelchart.activechart.charttype = 97
myexcelchart.activechart.barshape =3
myexcelchart.activechart.hastitle = true
myexcelchart.activechart.charttitle.text = "visitors log for each week shown in browsers percentage"
myexcelchart.activechart.setsourcedata myexcelchart.sheets("sheet1").range("a1:k5"),1
myexcelchart.activechart.location 1
myexcelchart.activechart.hasdatatable = true
myexcelchart.activechart.datatable.showlegendkey = true
save the the excelsheet to excelface
存入excel表
myexcelchart.saveas "c:\chart.xls"
%>
now lets complete the html tags.
下面是html代码
<html>
<head>
<title>myexcelchart</title>
</head>
<body>
</body>
</html>
this completes yer asp page, look below for the complete code of myexcelchart.asp
下面是源程序myexcelchart.asp的完整代码
<%@ language="vbscript" %>
<%
set myexcelchart = createobject("excel.sheet")
myexcelchart.application.visible = true
myexcelchart.activesheet.range("b2:k2").value = array("week1", "week2", "week3", "week4", "week5", "week6", "week7", "week8", "week9", "week10")
myexcelchart.activesheet.range("b3:k3").value = array("67", "87", "5", "9", "7", "45", "45", "54", "54", "10")
myexcelchart.activesheet.range("b4:k4").value = array("10", "10", "8", "27", "33", "37", "50", "54", "10", "10")
myexcelchart.activesheet.range("b5:k5").value = array("23", "3", "86", "64", "60", "18", "5", "1", "36", "80")
myexcelchart.activesheet.cells(3,1).value="internet explorer"
myexcelchart.activesheet.cells(4,1).value="netscape"
myexcelchart.activesheet.cells(5,1).value="other"
myexcelchart.activesheet.range("b2:k5").select
myexcelchart.charts.add
myexcelchart.activechart.charttype = 97
myexcelchart.activechart.barshape =3
myexcelchart.activechart.hastitle = true
myexcelchart.activechart.charttitle.text = "visitors log for each week shown in browsers percentage"
myexcelchart.activechart.setsourcedata myexcelchart.sheets("sheet1").range("a1:k5"),1
myexcelchart.activechart.location 1
myexcelchart.activechart.hasdatatable = true
myexcelchart.activechart.datatable.showlegendkey = true
myexcelchart.saveas "c:\chart.xls"
%>
<html>
<head>
<title>myexcelchart</title>
</head>
<body>
</body>
</html>
