ASP Programmer's Reference
WordTemplate.SetDataSource Method |
 |
SetDataSource(arrValues As Array, arrNames As Array)
Syntax:
Sub WordTemplate.SetDataSource(arrValues As Array, arrNames As Array)
Description:
Sets a template's data source to a one-dimensional array. This method
takes an array of values and an array of field names. The two
arrays must contain the same number of elements. Each name in the array of field
names must be the same as the corresponding merge field name in the template.
Each merge field in a WordWriter template must bind to a data source field/value pair.
The number of merge fields in the template may not exceed the number of values in the
data source. However, the number of values in the data source may be greater than the
number merge fields in the template.
In WordWriter 1.0, a template can have only one data source. Do not
call SetDataSource more than once for a single instance of WordTemplate.
|
Parameters:
- arrValues
An array of values to use as a data source. WordWriter
will insert these values in the template's merge fields.
- arrNames
An array of data source field names. These must be the same
as the corresponding merge field names in the template.
Example:
[VB]
Dim arrValues
Dim arrNames
Dim oWW
'--- Create an array of values. These values will be
'--- inserted in the template's merge fields.
arrValues = Array("SoftArtisans", "WordWriter", "http://www.softartisans.com")
'--- Create an array of field names. These must be the
'--- same as the corresponding merge field names in the template.
'--- The array of values and the array of names must contain
'--- the same number of elements.
arrNames = Array("CompanyName", "ProductName", "URL")
'--- Create an instance of WordTemplate.
Set oWW = Server.CreateObject("SoftArtisans.WordTemplate")
'--- Call the Open method to open the template file
oWW.Open(Server.MapPath("./Template.doc"))
'--- Set the data source of the document by passing
'--- the value array and the name array that we initialized above.
oWW.SetDataSource arrValues, arrNames
'--- Call WordTemplate.Process to populate the template with the
'--- new data.
oWW.Process
'--- Stream the generated file to the client.
oWW.Save Response, "ArrayVarsOutput.doc", False
'--- Clean Up
Set oWW = Nothing
Top
SetDataSource(RecordSet)
Syntax:
Sub WordTemplate.SetDataSource(oRS As RecordSet)
Description:
Sets a template's data source to an ADO recordset. If the specified
recordset contains more than one row, WordWriter will use the first row as
the data source.
In WordWriter 1.0, a template can have only one data source. Do not
call SetDataSource more than once for a single instance of WordTemplate.
|
Parameters:
- RecordSet
An ADO recordset to use as the data source.
WordWriter will use the first row of the
recordset as the data source.
Example:
[VB]
Dim oConn
Dim oRS
Dim strConnString
Dim oWW
Dim strSQL
'--- Set the connection string.
strConnString = Application("connString")
'--- SQL statement used to query the database
strSQL = "SELECT TOP 1 TitleOfCourtesy, FirstName, LastName, Title FROM Employees"
'--- Instantiate and open an ADO Connection,
'--- passing the connection string.
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open strConnString
'--- Query the database and get a RecordSet.
Set oRS = oConn.Execute(strSQL)
'--- Instantiate the WordWriter.WordTemplate object.
Set oWW = Server.CreateObject("SoftArtisans.WordTemplate")
'--- Call Open() to open the template file
oWW.Open Server.MapPath("./Template.doc")
'--- Pass the RecordSet object to SetDataSource().
oWW.SetDataSource oRS
'--- Call WordTemplate.Process() to populate the template
'--- with the new data.
oWW.Process
'--- Stream the generated Word file to the client.
oWW.Save Response, "DataTableOutput.doc", False
'--- Clean up
oRS.Close
oConn.Close
Set oRS = Nothing
Set oConn = Nothing
Set oWW = Nothing
Top
Copyright © 2003, SoftArtisans, Inc.