vbscript ms owc 封裝代碼
來(lái)源:易賢網(wǎng) 閱讀:1090 次 日期:2016-07-18 16:13:40
溫馨提示:易賢網(wǎng)小編為您整理了“vbscript ms owc 封裝代碼”,方便廣大網(wǎng)友查閱!

Office Web Components是一組的COM控件,設(shè)計(jì)的目的是為眾多的控件容器提供交互的電子表格建模,數(shù)據(jù)報(bào)表和數(shù)據(jù)可視化功能。

代碼如下:

''owc.vbs

class owc

private o

'傳入物件

public property set set_obj(o_id)

set o=o_id

end property

'畫(huà)圖矩形圖

'chart_bgcolor_圖表的背景顏色

'chartCaption_圖表的標(biāo)題

'chartCaption_fontColor_圖表標(biāo)題顏色

'Interior_Color_矩形內(nèi)的填充顏色

'Caption_名稱

'categories_名稱數(shù)組

'values_值數(shù)組串

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

'設(shè)背景色或是填充

o.Charts(0).PlotArea.Interior.SetSolid chart_bgcolor_

'加上圖表的標(biāo)題

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

'添加數(shù)據(jù)

cht.SetData c.chDimCategories, c.chDataLiteral, categories_

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

'直條的背景色進(jìn)行設(shè)定

set sc=o.Charts(0).SeriesCollection(0)

sc.Interior.Color=Interior_Color_

'直條上的顯示設(shè)置

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%"

'左邊百分比的屬性設(shè)置

Set cta = cht.Axes(c.chAxisPositionLeft)

cta.Font.Size = 9

cta.NumberFormat = "0.0%"

cta.MajorUnit = 0.1

end sub

'多系列矩形圖

'chart_bgColor_圖表的背景顏色

'chartCaption_圖表的標(biāo)題

'chartCaption_fontColor_圖表標(biāo)題顏色

'color_顏色數(shù)組

'caption_名稱數(shù)組

'categories_名稱數(shù)組

'values_值數(shù)組

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

'給繪圖區(qū)加背景色

o.Charts(0).PlotArea.Interior.SetSolid chart_bgColor_

''加上圖表的標(biāo)題

o.HasChartSpaceTitle = True

o.ChartSpaceTitle.Caption = chartCaption_

'標(biāo)題的屬性

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

'用循環(huán)來(lái)新增SeriesCollection以及里面的內(nèi)容

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

''圖例的設(shè)定

o.Charts(0).HasLegend = True

o.Charts(0).Legend.Font.Size = 9

o.Charts(0).Legend.Position = c.chLegendPositionBottom

''左邊百分比的屬性設(shè)置

Set cta = o.Charts(0).Axes(c.chAxisPositionLeft)

cta.Font.Size = 9

cta.NumberFormat = "0.00%"

cta.MajorUnit = 0.1

end sub

'畫(huà)圓餅圖

'chart_bgColor_繪圖區(qū)加背景色

'chartCaption_圖表的標(biāo)題

'chartCaption_fontColor_圖表標(biāo)題顏色

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

'給繪圖區(qū)加背景色

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_繪圖區(qū)加背景色

'chartCaption_圖表的標(biāo)題

'chartCaption_fontColor_圖表標(biāo)題顏色

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

'給繪圖區(qū)加背景色

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_圖表的標(biāo)題

'chartCaption_fontColor_圖表標(biāo)題顏色

'color_顏色數(shù)組

'caption_名稱數(shù)組

'categories_名稱數(shù)組

'values_值數(shù)組

public sub serLine(chart_bgColor_,chartCaption_,chartCaption_fontColor_,color_,SeriesNames_,categories_,values_)

o.Clear

Set cht = o.Charts.Add

Set c = o.Constants

'設(shè)置圖表類型

cht.Type = c.chChartTypeLineMarkers

'給繪圖區(qū)加背景色

o.Charts(0).PlotArea.Interior.Color=chart_bgColor_

'加上標(biāo)題

o.HasChartSpaceTitle = True

o.ChartSpaceTitle.Caption = chartCaption_

o.ChartSpaceTitle.Font.Color = chartCaption_fontColor_

o.ChartSpaceTitle.Font.Name = "Arial"

o.ChartSpaceTitle.Font.Size = 12

''添加數(shù)據(jù)

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

使用測(cè)試代碼:

代碼如下:

<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","報(bào)表標(biāo)題","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月坑頭三廠各周各樓層達(dá)成率比較圖","red",color,caption,categories,values

categories=array("臺(tái)北","上海")

values = array(238760,912560.62)

set t.set_obj=document.getElementById("cs3")

t.Pie "#FFFFFF","銷售金額所佔(zhàn)比例(城市分類)","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產(chǎn)品","B產(chǎn)品","C產(chǎn)品","D產(chǎn)品")

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","達(dá)成率月報(bào)表","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控件,設(shè)計(jì)的目的是為眾多的控件容器提供交互的電子表格建模,數(shù)據(jù)報(bào)表和數(shù)據(jù)可視化功能。OWC庫(kù)包含四個(gè)主要的組件:電子表格組件,圖表組件,透視表組件和數(shù)據(jù)源組件。

“Office Web Components”名稱中的單詞”O(jiān)ffice”表示這些控件就是由那些開(kāi)發(fā)微軟Excel和Access的程序員中的一部分人開(kāi)發(fā)的,并且這些控件被設(shè)計(jì)成在外觀,使用感受和行為表現(xiàn)上就像是他們的微軟Office兄弟的精簡(jiǎn)版一樣。這些控件確實(shí)不包含Excel和Access中的所有的功能——換句話說(shuō),你也不會(huì)為了在瀏覽器中查看一個(gè)報(bào)表而動(dòng)態(tài)的下載完整的Excel和Access,這些控件也確實(shí)包含了許多的常用功能,尤其是那些在與已有內(nèi)容進(jìn)行交互時(shí)所必需的功能。此外,這些控件還能夠讀寫(xiě)Excel 2000的HTML格式的文件,允許用戶點(diǎn)擊一個(gè)按鈕,將當(dāng)前的數(shù)據(jù)加載到Excel中,以便作更加強(qiáng)大的分析。

更多信息請(qǐng)查看腳本欄目
易賢網(wǎng)手機(jī)網(wǎng)站地址:vbscript ms owc 封裝代碼
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)