OWC introduction: Microsoft Office 2000 contains a set of new control collections called OWC. With these components, you can create many useful data analysis solutions with the report generated solutions in a web browser and other traditional programming environments.
Office Web Component is a set of Com (Component Object Model: Component Object Model) controls for providing interactive electronic data table models, database reports and data visualization services for multiple control containers.
The OWC library contains four main components: spreadsheet components, Chart (chart) components, PivotTable components, Data Source components.
The extraordinary of Office Web Components is that they can be used in control containers such as web pages, Visual Basic forms, or in memory as invisible objects. Most COM controls can only be used as visual controls in the control container, while most invisible objects can only be used in memory without placing in the form or in the web page. Components in the OWC library can be used in the above two ways, so that users can reference controls in an interface, or enable controls to provide basic services to them. The ability to use components in an invisible object can also be convenient to use this library on the server, making it easy to view static content on any web browser.
All controls in OWC support rich programming interface collections such that developers can call these controls through Microsoft VBScript, Microsoft JScript, Microsoft VBA, Java, C with any other language that can call two-way or fast COM interfaces.
Chart Components: The Chart component is a COM control created by developers created by the development of Chart in Microsoft Excel 2000. It can provide basic business chart production methods in two ways of the COM control on the screen with the GIF generating engine in memory.
In OWC9, the Chart control is supported in addition to all 2D chart types in Excel (except for the Contour type), the Polar type, Stacked PIE type, Filled Scatter type chart is supported. However, it does not contain support for any three-dimensional chart type or effect.
The version of Office Web Component provided by Office2000 is 9.0 (OWC9)
Office Web Component from OfficeXP is 10.0 (OWC10)
In the later series of tutorials, we use the Northwind database in SQL Server as an example, in-depth discussion to introduce MS OWC, and all examples can run directly.
We use an example to show the powerful function of OWC.
Chart.asp program.
<% OPTION Explicit%>
<%
Function ExportChartTogif (Objcspace, StrabsFilePath, StrrelFilePath)
DIM STRFILENAME
Randomize
Strfilename = Timer & Res & ".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>
<%
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 (".")
'Settings Components
'Using OWC9, it is the Office 2000
Set objChartSpace = Server.createObject ("Owc.chart.9")
Set objchart = objchartspace.Charts.add
SET C = ObjChartspace.Constants
'Graphic border color
ObjChart.Border.color = "red"
'Displaying the histogram
ObjChart.Type = 1
Objchart.haslegegend = true 'Display legend
Objchart.haastitle = true 'Show title
Objchart.title.caption = "Use Office Web Component to create a boutique chart (www.orrfly.com Chinese technology website)"
Set fnt = Objchart.title.font
FNT.NAME = "Song"
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
'What is the quantity of each supply?
Objrs.open "Select Count (ProductName) AS Col, CategoryName from Products, Categories WhereProducts.categoryId = Categories.categoryId Group by CategoryName
Set objChartSpace.DataSource = ObJRS
'Display legend content
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.CHAXISPSITIONBOTTOM)
Ax.hastitle = TRUE
Ax.title.caption = "Type"
Set fnt = ax.title.font
FNT.NAME = "Song"
FNT.SIZE = 15
FNT.BOLD = TRUE
FNT.COLOR = "blue"
SET AX = ObjChart.axes (C.chcategoryAxis)
Ax.hastitle = TRUE
Ax.title.caption = "Quantity"
Set fnt = ax.title.font
FNT.NAME = "Song"
FNT.SIZE = 15
FNT.BOLD = TRUE
FNT.COLOR = "Green"
Strchartfile = exportcharttogif (ObjchartAbspath, Strchartrelpath)
Response.write " & "
"
Cleanupgif StRCHARTABSPATH
Objrs.close
Set objrs = Nothing
Set objconn = Nothing
Set objseries = Nothing
Set objChart = Nothing
Set objChartspace = Nothing
%>
div>
Body>
Html>
Precautions for using this component: 1. On the Offic2000's CD, there is an executable file of MSOWC.MSI .ok 2. It is recommended that you use Visual InterDev6.0 development, and the automatic prompt function of the code will play a great role.