利用office web component打造精品图表

news/2024/7/21 5:49:58 标签: Office, Web, Excel, Microsoft, ASP
function StorePage() { d=document; t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():''); void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes')); keyit.focus(); }
利用office web component打造精品图表(一)

大家在编写ASP程序的时候,可能要对各
种指标以图形的方式显示出来。如果仅仅
是柱状图,可以采用画表格的方法。许多投票
程序多采用这种方法。如果是饼状图或从数据
库中检索数据后再显示,就有些困难了.办法
也有,自己可以封装excel来完成上述功能,或
者用deiphi做一个activeform传入参数,或者用php
来写,java也可以。当然,用一个比较成熟的图形
组件来完成更好一些。microsoftofficeweb
compoent非常不错。我在开发一个项目的时
候,用到了这个组件。

CHART.ASP程序。

<%OptionExplicit%>
<!--#includefile="adovbs.inc"-->
<HTML>
<HEAD>
<TITLE>柱状图的例子</TITLE>
<%
FunctionExportChartToGIF(objCSpace,strAbsFilePath,strRelFilePath)
DimstrFileName
Randomize
strFileName=Timer&Rnd&".gif"
objCSpace.ExportPicturestrAbsFilePath
&"\"&strFileName,"gif",650,400
ExportChartToGIF=strRelFilePath
&"/"&strFileName
EndFunction

SubCleanUpGIF(GIFpath)
DimobjFS
DimobjFolder
Dimgif
setobjFS=Server.CreateObject("Scripting.FileSystemObject")
setobjFolder=objFS.GetFolder(GIFpath)
foreachgifinobjFolder.Files
ifinstr(gif.Name,".gif")>0and
DateDiff("n",gif.DateLastModified,now)>10then
objFS.DeleteFileGIFpath&"\"&gif.Name,True
endif
next
setobjFolder=nothing
setobjFS=nothing
EndSub

%>
</HEAD>
<BODYBGCOLOR="#FFFFFF">
<divalign="center">
<br>
<br>
<%
dimsj1,sj2
sj1=Request.QueryString("s1")
sj2=Request.QueryString("s2")

dimobjChartSpace
dimobjChart
dimobjSeries
dimobjConn
dimobjRS
dimc
dimseries
dimstrChartAbsPath
dimstrChartRelPath
dimstrChartFile
dimaxis

strChartAbsPath=Server.MapPath("/xjsi-web/dcss/chart")
strChartRelPath="/xjsi-web/dcss/chart"
'设置组件

setobjChartSpace=Server.CreateObject("OWC.Chart")
setobjChart=objChartSpace.Charts.Add
setc=objChartSpace.Constants

objChartSpace.Border.Color="red"
'以柱状图显示
objchart.type=1
objChart.HasLegend=True'是否显示图例
objChartSpace.HasChartSpaceTitle=true'显示标题
objChartSpace.ChartSpaceTitle.Caption="柱状图的例子使用officeweb组件--www.ourfly.com中文技术网站"
setobjConn=Server.CreateObject("ADODB.Connection")
objConn.Openapplication("strconn")
setobjRS=Server.CreateObject("ADODB.Recordset")
setobjRS.ActiveConnection=objConn
objRS.CursorType=adOpenStatic
objRS.CursorLocation=adUseClient
objRS.Open"selectdwsj,sum(jfrs)asjfrs
fromdcss_do_jfgcfxbwheredwsj>='"&sj1&"'
anddwsj<'"&sj2&"'
groupbydwsjorderbydwsjasc"

setobjChartSpace.DataSource=objRS
'显示图例内容
objChart.SetDatac.chDimSeriesNames,0,"jfrs"
foreachobjSeriesinobjChart.SeriesCollection
objSeries.SetDatac.chDimCategories,0,"dwsj"
objSeries.SetDatac.chDimValues,0,"jfrs"
next

foreachaxisinobjChart.Axes
axis.HasTitle=True
ifaxis.Type=c.chCategoryAxisthen
axis.Title.Caption="月份"
else
axis.Title.Caption="人数"
endif
next

strChartFile=ExportChartToGIF(objChartSpace,strChartAbsPath,strChartRelPath)
Response.Write"<IMGSRC="""&strChartFile&""">"&"<P>"
CleanUpGIFstrChartAbsPath

objRS.Close
setobjRS=nothing
setobjConn=nothing
setobjSeries=nothing
setobjChart=nothing
setobjChartSpace=nothing
%>
</div>
</BODY>
</HTML>
使用这个组件的注意事项:
1。在office2000的光盘上,有一个msowc.msi的可执行文件.OK
2。建议大家用visualinterdev6.0开发,代码的自动提示功能此时会发挥出极大的作用。

效果图如下:

OWC介绍:

Microsoft Office 2000中包含有一组称为OWC的新控件集合。利用这些组件,可以在WEB浏览器以及其他传统的编程环境下创建许多有用的数据分析解决方案与报表生成解决方案。

Office Web Component是一组COM(Component Object Model:组件对象模型)控件的集合,用于为多种控件容器提供交互式的电子数据表模型、数据库报表与数据可视化服务。

OWC库中包含四个主要组件:Spreadsheet(电子数据表)组件、Chart(图表)组件、PivotTable(数据透视表)组件、Data Source(数据源)组件。

Office Web Components的非凡之处在于它们可以在诸如Web页面、Visual Basic表单等的控件容器中使用,也可在内存中作为不可见对象使用。大多数COM控件只能在控件容器中作为可视控件使用,而大多数不可见对象则只能在内存中使用,而不能放入表单中或Web页面中。OWC库中的组件可以以以上两种方式被使用,从而使得用户可以以界面方式引用控件,或者使控件为其提供基本服务。以不可见对象方式使用组件的能力也可以方便的在服务器上使用这个库,从而轻易的产生在任何Web浏览器上查看静态内容。

OWC中的所有控件都支持丰富的编程接口集合,使得开发者可以通过Microsoft VBScriptMicrosoft JscriptMicrosoft VBAJavaC++与任何其他可调用双向或快速COM接口的语言来调用这些控件。

Chart组件:

Chart组件是一个由开发Microsoft Excel 2000中图表制作的开发人员创建的一个COM控件。它能以屏幕上COM控件与内存中GIF生成引擎两种方式提供基本的商业图表制作方法。

OWC9中,Chart控件除支持Excel中的所有二维图表类型(Contour类型除外)外,还支持Polar型、Stacked Pie型、Filled Scatter型的图表。但是不包含对任何三维图表类型或效果的支持。

Office2000提供的Office Web Component的版本为9.0(OWC9)

OfficeXP提供的Office Web Component的版本为10.0(OWC10)

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

在以后的系列教程中,我们以sqlserver中的northwind数据库为例子,深入浅出的来介绍MS OWC,所有的例子直接可以运行。

我们通过一个例子来展现owc的强大功能.

CHART.ASP程序。

<% Option Explicit %>

<!--#include file="adovbs.inc"-->

<HTML>

<HEAD>

<TITLE>利用MS office web component打造精品图表</TITLE>

<%

Function ExportChartToGIF(objCSpace, strAbsFilePath, strRelFilePath)

Dim strFileName

Randomize

strFileName = Timer & Rnd & ".gif"

objCSpace.ExportPicture strAbsFilePath & "\" & strFileName, "gif", 650, 400

ExportChartToGIF = strRelFilePath & "/" & strFileName

End Function

Sub CleanUpGIF(GIFpath)

Dim objFS

Dim objFolder

Dim gif

set objFS = Server.CreateObject("Scripting.FileSystemObject")

set objFolder = objFS.GetFolder(GIFpath)

for each gif in objFolder.Files

if instr(gif.Name, ".gif") > 0 and DateDiff("n", gif.DateLastModified, now) > 10 then

objFS.DeleteFile GIFpath & "\" & gif.Name, True

end if

next

set objFolder = nothing

set objFS = nothing

End Sub

%>

</HEAD>

<BODY BGCOLOR="#FFFFFF">

<div align="center">

<br>

<br>

<%

dim objChartSpace

dim objChart

dim objSeries

dim objConn

dim objRS

dim c

dim series

dim strChartAbsPath

dim strChartRelPath

dim strChartFile

dim axis

dim fnt

dim ax

strChartAbsPath = Server.MapPath(".")

strChartRelPath = Server.MapPath(".")

'设置组件

'使用了owc9,也就是office 2000中带的

set objChartSpace = Server.CreateObject("OWC.Chart.9")

set objChart = objChartSpace.Charts.Add

set c = objChartSpace.Constants

'图形边框颜色

objchart.Border.Color="red"

'以柱状图显示

objchart.type=1

objChart.HasLegend = True'是否显示图例

objChart.HasTitle=true '显示标题

objChart.Title.Caption ="利用office web component打造精品图表(www.ourfly.com中文技术网站)"

set fnt=objchart.title.font

fnt.name="宋体"

fnt.size=12

fnt.bold=true

fnt.color="red"

set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open "provider=SQLOLEDB; Data Source=yang; Initial Catalog=northwind; User Id=sa; Password="

set objRS = Server.CreateObject("ADODB.Recordset")

set objRS.ActiveConnection = objConn

objRS.CursorType = adOpenStatic

objRS.CursorLocation = adUseClient

'统计每种供应货物的数量有多少

objRS.Open "select count(productname) as col,
CategoryName from products,categories whereproducts.categoryid=categories.categoryid
group by categoryname"

set objChartSpace.DataSource = objRS

'显示图例内容

objChart.SetData c.chDimSeriesNames, 0, "CategoryName"

for each objSeries in objChart.SeriesCollection

objSeries.SetData c.chDimCategories, 0, "CategoryName"

objSeries.SetData c.chDimValues, 0, "col"

next

set ax=objChart.Axes(c.chAxisPositionBottom)

ax.hastitle=true

ax.Title.Caption = "种类"

set fnt=ax.title.font

fnt.name="宋体"

fnt.size=15

fnt.bold=true

fnt.color="blue"

set ax=objChart.Axes(c.chCategoryAxis)

ax.hastitle=true

ax.Title.Caption = "数量"

set fnt=ax.title.font

fnt.name="宋体"

fnt.size=15

fnt.bold=true

fnt.color="green"

strChartFile = ExportChartToGIF(objChartSpace, strChartAbsPath, strChartRelPath)

Response.Write "<IMG SRC=""" & strChartFile & """>" & "<P>"

CleanUpGIF strChartAbsPath

objRS.Close

set objRS = nothing

set objConn = nothing

set objSeries = nothing

set objChart = nothing

set objChartSpace = nothing

%>

</div>

</BODY>

</HTML>

使用这个组件的注意事项:
1
。在office2000的光盘上,有一个msowc.msi的可执行文件
.OK
2
。建议大家用visualinterdev6.0开发,代码的自动提示功能
此时会发挥出极大的作用。


效果图如下:



http://www.niftyadmin.cn/n/607269.html

相关文章

poj1555

简单题 View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 10int f[maxn];void input(){for (int i 1; i < 9; i) scanf("%d", &f[i]);}void print(){…

modelarts二

一、导入数据 创建声音分类项目 数据标注&#xff08;分标签&#xff09;后进行模型训练 训练完成后进行部署 二、对于文本分类 进入更多&#xff0c;文本、标签分开 之后再 之后部署然后检测

使用C#创建webservice及三种调用方式

function StorePage() { ddocument; td.selection?(d.selection.type!None?d.selection.createRange().text:):(d.getSelection?d.getSelection():); void(keyitwindow.open(http://www.365key.com/storeit.aspx?tescape(d.title)&uescape(d.location.href)&cescap…

java mysql教程基于_SpringBoot入门教程(五)Java基于MySQL实现附近的人

“附近的人”这个功能估计都不陌生&#xff0c;与之类似的功能最开始是在各大地图应用上接触过&#xff0c;比如搜附近的电影院&#xff0c;附近的超市等等。然而真正让附近的人火遍大江南北的应该是微信"附近的人"这个功能&#xff0c;记得微信刚出的时候&#xff0…

MSMQ的简单介绍(收藏)

function StorePage() { ddocument; td.selection?(d.selection.type!None?d.selection.createRange().text:):(d.getSelection?d.getSelection():); void(keyitwindow.open(http://www.365key.com/storeit.aspx?tescape(d.title)&uescape(d.location.href)&cescap…

python100道编写程序_Python入门100道习题(8)——矩阵乘法

题目描述【问题描述】编写程序&#xff0c;完成3*&#xff14;矩阵和4*&#xff13;整数矩阵的乘法&#xff0c;输出结果矩阵。【输入形式】一行&#xff0c;供24个整数。以先行后列顺序输入第一个矩阵&#xff0c;而后输入第二个矩阵。【输出形式】先行后列顺序输出结果矩阵&a…

7_21多个字段进行相连

select * from SYSUT_MsgIAItem --7_21事情增加字段 insert into SYSUT_MsgIAItem values (MQ_SEQPLAN,*, ,新的序计划,*, ,DIS,*,有新的滚动序计划&#xff0c;请注意查收&#xff01;,I,有新的滚动序计划&#xff0c;请注意查收&#xff01;, , , , , , , , , , , ); insert…

harmonyos培训一

基本内容&#xff1a; 配置对应的 SDK 版本 在 DevEco Studio 菜单栏&#xff0c;点击Tools > SDK Manager浏览软件页面&#xff1a;View——tool Windows——previewer 解除软件页面的锁定&#xff1a;右上角——设置——view mode——float真机测试&#xff1a; 进入 Tool…