vbscript ms owc 封裝代码

代码如下:

''owc.vbs
class owc
private o
'传入物件
public property set set_obj(o_id)
set o=o_id
end property
'画图矩形图
'chart_bgcolor_图表的背景颜色
'chartCaption_图表的标题
'chartCaption_fontColor_图表标题颜色
'Interior_Color_矩形内的填充颜色
'Caption_名称
'categories_名称数组
'values_值数组串
public sub bar(chart_bgcolor_,chartCaption_,chartCaption_fontColor_,Interior_Color_,Caption_,categories_,values_)
o.Clear
set cht = o.Charts.Add
set c = o.Constants
cht.Type = c.chChartTypeColumnClustered
'设背景色或是填充
o.Charts(0).PlotArea.Interior.SetSolid chart_bgcolor_

'加上图表的标题
o.HasChartSpaceTitle = True
set cst=o.ChartSpaceTitle
cst.Caption = chartCaption_
cst.Font.Color = chartCaption_fontColor_
cst.Font.Italic = False
cst.Font.Name = "Arial"
cst.Font.Size = 12
cst.Font.Underline = c.owcUnderlineStyleSingle

'添加数据
cht.SetData c.chDimCategories, c.chDataLiteral, categories_
cht.SeriesCollection(0).SetData c.chDimValues, c.chDataLiteral, values_
'直条的背景色进行设定
set sc=o.Charts(0).SeriesCollection(0)
sc.Interior.Color=Interior_Color_

'直条上的显示设置
sc.Caption=Caption_
set dl = cht.SeriesCollection(0).DataLabelsCollection.Add
dl.HasValue = True
dl.HasPercentage = False
dl.Font.Size = 9
dl.Font.Color = "red"
dl.Position = c.chLegendPositionRight
dl.NumberFormat = "00.00%"
'左边百分比的属性设置
Set cta = cht.Axes(c.chAxisPositionLeft)
cta.Font.Size = 9
cta.NumberFormat = "0.0%"
cta.MajorUnit = 0.1
end sub
'多系列矩形图
'chart_bgColor_图表的背景颜色
'chartCaption_图表的标题
'chartCaption_fontColor_图表标题颜色
'color_颜色数组
'caption_名称数组
'categories_名称数组
'values_值数组
public sub serBar(chart_bgColor_,chartCaption_,chartCaption_fontColor_,color_,caption_,categories_,values_)
o.Clear
o.Charts.Add
Set c = o.Constants
'图表的类型
o.Charts(0).type=c.chChartTypeColumnClustered
'给绘图区加背景色
o.Charts(0).PlotArea.Interior.SetSolid chart_bgColor_
''加上图表的标题
o.HasChartSpaceTitle = True
o.ChartSpaceTitle.Caption = chartCaption_
'标题的属性
o.ChartSpaceTitle.Font.Color = chartCaption_fontColor_
o.ChartSpaceTitle.Font.Italic = False
o.ChartSpaceTitle.Font.Name = "Arial"
o.ChartSpaceTitle.Font.Size = 12
o.ChartSpaceTitle.Font.Underline = c.owcUnderlineStyleSingle
'用循环来新增SeriesCollection以及里面的内容
for i=0 to ubound(caption_)
valuetemp=""
for j = i*(ubound(categories_)+1) to (i+1)*(ubound(categories_)+1)-1
valuetemp = valuetemp & "," & values_(j)
next
valuearr = split(mid(valuetemp,2),",")
o.Charts(0).SeriesCollection.Add
o.Charts(0).SeriesCollection(i).Caption = caption_(i)
o.Charts(0).SeriesCollection(i).Interior.Color = color_(i)
o.Charts(0).SeriesCollection(i).SetData c.chDimCategories, c.chDataLiteral, categories_
o.Charts(0).SeriesCollection(i).SetData c.chDimValues, c.chDataLiteral, valuearr
set dl = o.Charts(0).SeriesCollection(i).DataLabelsCollection.Add
dl.HasValue = True
dl.HasPercentage = False
dl.Font.Size = 9
dl.Font.Color = "red"
dl.Position = c.chLegendPositionRight
dl.NumberFormat = "00.00%"
next
''图例的设定
o.Charts(0).HasLegend = True
o.Charts(0).Legend.Font.Size = 9
o.Charts(0).Legend.Position = c.chLegendPositionBottom
''左边百分比的属性设置
Set cta = o.Charts(0).Axes(c.chAxisPositionLeft)
cta.Font.Size = 9
cta.NumberFormat = "0.00%"
cta.MajorUnit = 0.1
end sub
'画圆饼图
'chart_bgColor_绘图区加背景色
'chartCaption_图表的标题
'chartCaption_fontColor_图表标题颜色
public sub Pie(chart_bgColor_,chartCaption_,chartCaption_fontColor_,Caption_,categories_,values_)
o.Clear
Set cht = o.Charts.Add
Set c = o.Constants
cht.Type = c.chChartTypePie3d
'给绘图区加背景色
o.Charts(0).PlotArea.Interior.SetSolid chart_bgColor_
cht.ExtrudeAngle = 90
cht.ChartDepth = 169
cht.AspectRatio = 120
cht.Rotation =180
cht.Inclination=70

o.HasChartSpaceTitle = True
o.ChartSpaceTitle.Caption = chartCaption_
o.ChartSpaceTitle.Font.Color = chartCaption_fontColor_
o.ChartSpaceTitle.Font.Name = "Arial"
o.ChartSpaceTitle.Font.Size = 12
o.ChartSpaceTitle.Font.Underline = c.owcUnderlineStyleSingle

cht.HasLegend = True
cht.Legend.Font.Size = 9
cht.Legend.Position = c.chLegendPositionBottom

cht.SetData c.chDimCategories, c.chDataLiteral, categories_
cht.SeriesCollection(0).SetData c.chDimValues, c.chDataLiteral, values_
set sc=o.Charts(0).SeriesCollection(0)
sc.Caption=Caption_
Set dl = cht.SeriesCollection(0).DataLabelsCollection.Add
dl.Separator = ":"
dl.HasValue = false
dl.HasSeriesName = false
dl.HasCategoryName=true
dl.HasPercentage = true
dl.Font.Size = 9
dl.Font.Color = "red"
dl.NumberFormat = "00.00%"
end sub
'拆线图
'chart_bgColor_绘图区加背景色
'chartCaption_图表的标题
'chartCaption_fontColor_图表标题颜色
public sub line(chart_bgColor_,chartCaption_,chartCaption_fontColor_,Caption_,categories_,values_)
o.Clear
Set cht = o.Charts.Add
Set c = o.Constants
cht.Type = c.chChartTypeLineMarkers
'给绘图区加背景色
o.Charts(0).PlotArea.Interior.SetSolid chart_bgColor_
o.HasChartSpaceTitle = True
o.ChartSpaceTitle.Caption = chartCaption_
o.ChartSpaceTitle.Font.Color = chartCaption_fontColor_
o.ChartSpaceTitle.Font.Name = "Arial"
o.ChartSpaceTitle.Font.Size = 12
o.ChartSpaceTitle.Font.Underline = c.owcUnderlineStyleSingle

cht.SetData c.chDimCategories, c.chDataLiteral, categories_
cht.SeriesCollection(0).SetData c.chDimValues, c.chDataLiteral, values_

set sc=o.Charts(0).SeriesCollection(0)
sc.Caption=Caption_
Set dl = cht.SeriesCollection(0).DataLabelsCollection.Add
dl.HasValue = True
dl.HasPercentage = False
dl.Font.Size = 9
dl.Font.Color = "red"

Set categoryAxis = cht.Axes(c.chAxisPositionBottom)
categoryAxis.Font.Size = 9

Set categoryAxis = cht.Axes(c.chAxisPositionLeft)
categoryAxis.Font.Size = 9
end sub
'多系列拆线图
'chart_bgColor_图表的背景颜色
'chartCaption_图表的标题
'chartCaption_fontColor_图表标题颜色
'color_颜色数组
'caption_名称数组
'categories_名称数组
'values_值数组
public sub serLine(chart_bgColor_,chartCaption_,chartCaption_fontColor_,color_,SeriesNames_,categories_,values_)
o.Clear
Set cht = o.Charts.Add
Set c = o.Constants
'设置图表类型
cht.Type = c.chChartTypeLineMarkers
'给绘图区加背景色
o.Charts(0).PlotArea.Interior.Color=chart_bgColor_
'加上标题
o.HasChartSpaceTitle = True
o.ChartSpaceTitle.Caption = chartCaption_
o.ChartSpaceTitle.Font.Color = chartCaption_fontColor_
o.ChartSpaceTitle.Font.Name = "Arial"
o.ChartSpaceTitle.Font.Size = 12
''添加数据
cht.SetData c.chDimSeriesNames, c.chDataLiteral, SeriesNames_
cht.SetData c.chDimCategories, c.chDataLiteral, Categories_

set categoryAxis = cht.Axes(c.chAxisPositionBottom)
categoryAxis.Font.Size = 9

Set categoryAxis = cht.Axes(c.chAxisPositionLeft)
categoryAxis.Font.Size = 9

for i = 0 to ubound(SeriesNames_)
valuetemp = ""
for j = i*(ubound(Categories_)+1) to (i+1)*(ubound(Categories_)+1)-1
valuetemp = valuetemp & "," & values_(j)
next
valuearr = split(mid(valuetemp,2),",")
cht.SeriesCollection(i).SetData c.chDimValues, c.chDataLiteral, valuearr
cht.SeriesCollection(i).Line.Color = color_(i)
cht.SeriesCollection(i).Line.Weight = c.owcLineWeightThin
cht.SeriesCollection(i).Marker.Style = c.chMarkerStyleDiamond
cht.SeriesCollection(i).Interior.Color = color_(i)
Set dl = cht.SeriesCollection(i).DataLabelsCollection.Add
dl.HasValue = true
dl.HasPercentage = false
dl.Font.Size = 9
dl.font.color="red"
next
end sub
'清除图型
public sub clear()
o.Clear
end sub
end class

使用测试代码:


代码如下:

<html>
<head>
<title>vbscript owc class test</title>
<script language="vbscript" src="owc.vbs"></script>
<script language="vbscript">
sub window_onload()
set t = new owc

categories =Array("A2-1","A2-2","A2-3","A3-1","A3-2","A3-3"_
,"B2-1","B2-2","B2-3","B3-1","B3-2","B3-3"_
,"C2-1","C2-2","C3-1","C3-2","C3-3")
values = Array(0.813,0.689,0.800,0.833,0.681,0.864,0.743_
,0.894,0.822,0.874,0.746,0.908,0.850_
,0.728,0.731,0.734,0.624)
set t.set_obj=document.getElementById("cs1")
t.bar "#FFFFFF","报表标题","BLUE","#CCCC00","组别",categories,values

color=Array("#CCFFFF","#99CCFF","#00CCFF","#FF0000","#660066","#FF8080")
caption=Array("第1周","第2周","第3周","第4周")
categories=Array("A栋","B栋")
values=Array(0.6951,0.5798,0.7075,0.512,0.7907,0.7493,0.8691,0.7716)
set t.set_obj=document.getElementById("cs2")
t.serbar "#FFFFFF","2008年10月坑头三厂各周各楼层达成率比较图","red",color,caption,categories,values

categories=array("台北","上海")
values = array(238760,912560.62)
set t.set_obj=document.getElementById("cs3")
t.Pie "#FFFFFF","销售金额所佔比例(城市分类)","BLUE","城市",categories,values

categories =array("2008/11/1","2008/11/2","2008/11/3","2008/11/4","2008/11/5","2008/11/6","2008/11/7","2008/11/8","2008/11/9","2008/11/10","2008/11/11","2008/11/12","2008/11/13","2008/11/14","2008/11/15","2008/11/16","2008/11/17","2008/11/18","2008/11/19","2008/11/20","2008/11/21","2008/11/22","2008/11/23","2008/11/24","2008/11/25","2008/11/26","2008/11/27","2008/11/28","2008/11/29","2008/11/30")
values = array(67239.89,60400.26,7202.89,18453.12,28889.29,102136.25,78826.39,146291.6,93743.29,44204.44,45349.28,50730.6,37900.21,84359.87,169333.62,114594.96,75334.77,51360.32,55853.05,37912.63,45068.22,63930.98,72993.71,18699.5,24714.5,34792.91,39414.58,92171.2,74433.06,3998894.41)
set t.set_obj=document.getElementById("cs4")
t.line "#FFFFFF","销售金额","BLUE","日期",categories,values

color=Array("#CCFFFF","#99CCFF","#00CCFF","#FF0000")
SeriesNames = array("A产品","B产品","C产品","D产品")
Categories = array("2005/3/24","2005/3/25","2005/3/26","2005/3/27","2005/3/28")
values = array(50,100,20,80,89,40,60,20,90,70,20,50,55,25,60,80,20,75,58,100)
set t.set_obj=document.getElementById("cs5")
t.serline "#FFFFFF","达成率月报表","red",color,SeriesNames,categories,values

set t=nothing
end sub
</script>
</head>
<body>
<div id="c1"><object id="cs1" name="cs1" classid="CLSID:0002E55D-0000-0000-C000-000000000046" codebase="owc11.dll" style="width:100%;height:350"></object></div>
<div id="c2"><object id="cs2" name="cs2" classid="CLSID:0002E55D-0000-0000-C000-000000000046" codebase="owc11.dll" style="width:100%;height:350"></object></div>
<div id="c3"><object id="cs3" name="cs3" classid="CLSID:0002E55D-0000-0000-C000-000000000046" codebase="owc11.dll" style="width:100%;height:350"></object></div>
<div id="c4"><object id="cs4" name="cs4" classid="CLSID:0002E55D-0000-0000-C000-000000000046" codebase="owc11.dll" style="width:100%;height:350"></object></div>
<div id="c5"><object id="cs5" name="cs5" classid="CLSID:0002E55D-0000-0000-C000-000000000046" codebase="owc11.dll" style="width:100%;height:350"></object></div>
</body>
</html>

owc是什么?
Office Web Components是一组的COM控件,设计的目的是为众多的控件容器提供交互的电子表格建模,数据报表和数据可视化功能。OWC库包含四个主要的组件:电子表格组件,图表组件,透视表组件和数据源组件。
  “Office Web Components”名称中的单词”Office”表示这些控件就是由那些开发微软Excel和Access的程序员中的一部分人开发的,并且这些控件被设计成在外观,使用感受和行为表现上就像是他们的微软Office兄弟的精简版一样。这些控件确实不包含Excel和Access中的所有的功能——换句话说,你也不会为了在浏览器中查看一个报表而动态的下载完整的Excel和Access,这些控件也确实包含了许多的常用功能,尤其是那些在与已有内容进行交互时所必需的功能。此外,这些控件还能够读写Excel 2000的HTML格式的文件,允许用户点击一个按钮,将当前的数据加载到Excel中,以便作更加强大的分析。

(0)

相关推荐

  • vbscript ms owc 封裝代码

    复制代码 代码如下: ''owc.vbs class owc private o '传入物件 public property set set_obj(o_id) set o=o_id end property '画图矩形图 'chart_bgcolor_图表的背景颜色 'chartCaption_图表的标题 'chartCaption_fontColor_图表标题颜色 'Interior_Color_矩形内的填充颜色 'Caption_名称 'categories_名称数组 'values_值数

  • VBScript 动态 Array 的实现代码

    记录一个小方法,关于 VBScript 中,动态 Array 的实现,也适用于 VBA, 在很久以前,写 VBA 的时候,就觉得使用 Array 和不方便,因为大小固定, 当时想的是,要是 Array 可以像 Python 里的 list 一样好用该多好啊, 那么下面,就记录一个方法,能让 Array 变得动态,并且好用! 实现方法: 在下面的实例中,先设定一个空的 Array 出来, 然后用,下面的方法实现动态 Array, 并且,把数字 1 到 10,一个加到 Array 中去. '动态 A

  • VbScript 封裝MS OWC(二)

    复制代码 代码如下: ''OWC1.VBS class owc private o '傳入物件 public sub create(id_,width_,height_,location_) Set o = document.createElement("object") o.setAttribute "id",id_ o.setAttribute "classid","CLSID:0002E55D-0000-0000-C000-000

  • vbscript include的办法实现代码第1/2页

    任何真正实用的工程开发都必然是多文件的.但是VBScript创建多文件工程要麻烦一点,它对多文件工程,代码复用的支持并不是太好.在C/C++工程里,我们已经习惯了通过一个include语句,并且声明一个函数原形的方式来使用其它模块中的函数,这样一个复杂的工程可以比较容易地分解成一些小的模块,以更容易理解和掌握.VBScript中情况有些不同.这与它的设计目标有关.最初VBScript是用在客户端脚本,以支持与客户端作简单的交互,如简单的输入检查等等.在浏览器里显然没有办法支持对另一个文件中的函数

  • Microsoft VBScript 编译器错误 错误原因 代码大全

    Microsoft VBScript 编译器错误 错误 '' 缺少语句 ActiveServerPages,ASP0126(0x80004005)-->找不到包含文件 MicrosoftOLEDBProviderforODBCDrivers(0x80040E21)-->sql语句出错(数据类型不匹配或表名(字段名)错误或表处于编辑状态,或表不存在于conn打开的数据库中) MicrosoftOLEDBProviderforODBCDrivers(0x80040E14)-->sql语句出错

  • IE中用VBScript不提示直接打印的代码

    首先在HTML 页面中加入WebBrowser 的Object: <OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT> 之后,使用如下代码进行打印: <script language="VBScript"> sub printvb() wb.execwb 6,2,3 End Sub

  • VBScript Enun Remote CMD Shell代码

    效果如图: 复制代码 代码如下: '============================' Enun Remote CMDShell v 1.0'============================ Option Explicit CONST ACCOUNT_LOCK_TIME = 600000    '账户锁定时间,10分钟CONST LOCKOUT_BAD_COUNT = 3     '密码失败次数CONST DEFAULT_WAIT_TIME = 1000     '默认延时,1秒

  • vbscript自动配置IIS的代码

    复制代码 代码如下: strServerName =""localhost"" strRootPath=""g:\documents"" ''虚拟目录路径 strVRName=""Test"" ''虚拟目录名称 strDefaultDoc=""index.asp"" ''起始文档 Dim objIIS ''MsgBox ""II

  • vbscript网页模拟登录效果代码

    闲的蛋疼今天~ 电脑浏览器记住密码功能好蛋疼~有时候不好用~~登录CMCC-EDU的时候老是要输入帐号..看了看登录页面的网页源码~~撸起个Vbs脚本~读取配置文件,简单实现了自己登录CMCC-EDU,把帐号存在同级目录下就好.一行帐号,一行密码. 好久不用vbs~都忘记了快~~ '自动登录CMCC-EDU 'By:Seven 2014/2/25 On Error Resume Next Set WshShell = CreateObject("wscript.Shell") Set

  • asp怎么获取毫秒数实现代码

    复制代码 代码如下: <%@ Language=VBScript %><%Response.Expires =0 %> <DOCTYPE html public='-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <HTML xmlns="http://www.w3.org/1999/xh

随机推荐