帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
ASP与电子表格EXCEL的交互操作
作者: 发布时间:2005-03-12 来源:
Here we go again with another sample for Excel, this time we will be using ASP to create a chart. You all
asked me for it, now here is the solution. Thanks again for all your nice comments :)

First we set the type of script

<%@ LANGUAGE="VBSCRIPT" %>

Make the object, and set the object to an Excelsheet

Dim MyExcelChart
Set MyExcelChart = CreateObject("Excel.Sheet")

Now lets write the rest of the script, see the comments

' show or dont show excel to user, TRUE or FALSE
MyExcelChart.Application.Visible = True

' populate the cells
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
MyExcelChart.ActiveSheet.Range("b2:k5").Select
    
' Add the 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
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
MyExcelChart.SaveAs "c:chart.xls"
%>

Now lets complete the HTML tags.

<HTML>
<HEAD>
<TITLE>MyExcelChart</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>

This completes yer ASP page, look below for the complete code of myexcelchart.asp

<%@ LANGUAGE="VBSCRIPT" %>
<%
' Create Object
Set MyExcelChart = CreateObject("Excel.Sheet")

' show or dont show excel to user, TRUE or FALSE
MyExcelChart.Application.Visible = True

' populate the cells
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
MyExcelChart.ActiveSheet.Range("b2:k5").Select
    
' Add the 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
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 chart.xls
MyExcelChart.SaveAs "c:chart.xls"


%>
<HTML>
<HEAD>
<TITLE>MyExcelChart</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>
  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·ASP与数据库运用:密码验证  (2005-03-12)
 ·何让你的ASP运行于非Windows平台  (2005-03-12)
 ·如何让你的ASP运行于非Windows平  (2005-03-12)
 ·如何让你的ASP运行于非Windows平  (2005-03-12)
 ·如何让你的ASP运行于非Windows平  (2005-03-12)
 ·如何让你的ASP运行于非Windows平  (2005-03-12)
 ·如何让你的ASP运行于非Windows平  (2005-03-12)
 ·如何让你的ASP运行于非Windows平  (2005-03-12)
 ·在ASP与ASP.NET之间共享对话状态  (2005-03-12)
 ·在ASP与ASP.NET之间共享对话状态  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统