Forums     Knowledge Base     OfficeWriter Online     
 
 
This documentation is for
OfficeWriter v3.6.1
.NET Platform

View Docs for Another
Version or Platform

Programmer's Reference > WordTemplate > Process Method

Process Method

C# Syntax:

public void Process();

VB.NET Syntax:

Public Sub Process()

Object:

Description:

The Process method enters data source values in a template's merge fields, and creates an image of the output file (the new document) in memory. The save method can then save the output file to disk, stream it to the browser, or both.

Call Process after SetDataSource and before Save.

You can call Process more than once for a single instance of WordTemplate. This allows you to generate multiple files from a single template and an updated data source.

Examples:

  • Generate a single Word file

    [VB.NET]
    	
    '--- Create an object array of values 
    '--- and a string array of field names to pass to 
    '--- SetDataSource.
    Dim arrValue As Object() = {"SoftArtisans WordWriter"}
    Dim arrName As String() = {"ProductName"}
    
    '--- Create an instance of WordTemplate.
    Dim oWW As WordTemplate = Nothing
    oWW = New WordTemplate()
    
    '--- Open a template file.
    oWW.Open(Server.MapPath("./StringVarTemplate.doc"))
    
    '--- Set the file's data source by passing 
    '--- SetDataSource an array of values and an 
    '--- array of merge field names.
    oWW.SetDataSource(arrValue, arrName)
    
    '--- Call Process() to populate the template with 
    '--- the new data.
    oWW.Process()
    
    '--- After processing the template, call Save() and pass it 
    '--- Page.Response to stream the generated file to the browser.
    oWW.Save(Page.Response, "StringVarOutput.doc", False)
  • Create multiple Word files from a single template and an updated data source

    [VB.NET]
    	
    Dim oWW As WordTemplate = Nothing
    oWW = New WordTemplate()
    	
    oWW.Open(Server.MapPath("./DataSourceUpdateTemplate.doc"))
    	
    '--- Set an object array of values to enter in 
    '--- the template's merge fields.
    Dim arrValue As Object() = {"SoftArtisans", "WordWriter", _ 
    	"http://www.softartisans.com"}
    		
    '--- Set a string array of merge field names.
    Dim arrName As String() = {"CompanyName", "ProductName", "URL"}
    
    '--- Set the data source of the document by passing
    '--- the value array and the name array initialized above.
    oWW.SetDataSource(arrValue, arrName)
    
    '--- Call Process() to populate the template with the data.
    oWW.Process()
    
    '--- After calling Process(), pass the Save method a string file name 
    '--- to save the generated file on the server.
    oWW.Save(Server.MapPath("./DataSourceUpdateOutput-1.doc"))
    
    '--- Now, update the data source by modifying the elements of 
    '--- the arrValues array.
    arrValue(0) = "SoftArtisans, Inc."
    arrValue(1) = "WordWriter.WordTemplate"
    arrValue(2) = "www.softartisans.com"
    
    '--- Call Process() again to populate the open
    '--- template with the updated data source.
    oWW.Process()
    
    '--- Save the updated document.
    oWW.Save(Server.MapPath("./DataSourceUpdateOutput-2.doc"))



Copyright 2006 © SoftArtisans, Inc. All Rights Reserved.