vbscript ms owc 封裝代码
来源: 阅读:1113 次 日期:2016-07-18 16:13:40
温馨提示: 小编为您整理了“vbscript ms owc 封裝代码”,方便广大网友查阅!

Office Web Components是一组的COM控件,设计的目的是为众多的控件容器提供交互的电子表格建模,数据报表和数据可视化功能。

代码如下:

''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中,以便作更加强大的分析。

更多信息请查看脚本栏目
手机网站地址:vbscript ms owc 封裝代码
由于各方面情况的不断调整与变化, 提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:
咨询QQ:526150442(9:00—18:00)版权所有:
云南网警报警专用图标
Baidu
map