Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

These guides cover WordWriter's features in more depth. If you are getting started with WordWriter, it is recommended that you start with the Hello World and the Basic tutorials first.
WordApplication Guides

Creating a Paragraph

To insert a paragraph in a section of your document, use one of the following methods. All of the methods insert a parapraph at a specified point in an Element. An Element object represents an editable region in a document, such as a section or a table cell. The document itself is an Element (the Document class extends Element). Later we will add a paragraph to a Document object.

Formatting Text

This article covers applying fonts, named styles, paragraph formatting and table formatting.

Creating Lists

To add a list to a section of your document, use one of the following methods. All of the methods insert a list at a specified point in an Element. An Element object represents an editable region in a document, such as a section or a table cell. The document itself is an Element (the Document class extends Element). Later, we will add a list to a Document object.

Creating Tables

To add a table to a section of your document, use one of the following methods. All of the methods insert a table at a specified point in an Element. An Element object represents an editable region in a document, such as a section or paragraph. The document itself is an Element.

Creating Sections

A Section object represents a major section in a document, like a chapter in a book. Many documents will only contain one section. In more complex documents, content can be divided into multiple sections.

Adding Images

To insert an image into a section of your document, use one of the following methods. Each method inserts an image at the beginning or end of an Element. An Element object represents an editable region in a document, such as a section or paragraph. The document itself is an Element.

Inserting Watermarks

A watermark is an image or text that when printed appears in the background of a document. The watermark text or image is faded so that it does not distract from the content of the document but is legible.

Importing Data

WordApplication's ImportData method allows you to import blocks of data to a worksheet from a database or a rectangular array. ImportData is a method of both Element and Table. Element.importData returns a Table object representing a table in the document that contains the imported data.Table.importData adds an new row to an existing table.

WordApplication Output Options

WordApplication offers a variety of different options for saving your WordWriter generated document.

Unfolding a Word document with WordApplication Sample

The code below provides a function "UnfoldDocument" which will produce a formatted text representation of the element hierarchy in a given Document. Output assumes a monospaced font and is suitable for writing to a plain-text file, printing to a console or inserting in a tag on an ASP.Net page.

 


 

WordTemplate Guides

Creating a Template

OfficeWriter's WordTemplate object opens a WordWriter template file, populates it with data from one or more data sources, and generates a new Word file. A WordWriter template is a file created in Microsoft Word that contains merge fields. A merge field displays a data source field name (for example, a database column name) where a data source value will be inserted. Merge fields are bound to a data source in OfficeWriter code. When you run the code, OfficeWriter replaces the merge fields with v

Creating Merge Fields

A WordWriter template is a Microsoft Word file that contains merge fields. A merge field displays a data source field (for example, a database column name). A merge field is created in Microsoft Word and bound in code to a data source. The data source may be an array, a DataSet, a DataTable, or a DataReader. When you run the code, WordWriter populates the merge fields with data source values.

Formatting Merge Fields

When you create a merge field in Microsoft Word (see Creating a WordWriter Template), you can apply formatting to the field. For example, you can set a merge field's format to "Uppercase" to display the field's value in uppercase letters. WordWriter supports most text, date, and time formats available in Microsoft Word.

Inserting an Image

WordWriter allows you to insert jpg, gif, bmp, and png images in merge fields. You can insert images repeat block and main document merge fields. There are two ways to insert an image into a merge field:

Adding Formulas to a Document

Beginning in WordWriter version 4.1, WordTemplate now has the ability to evaluate a certain number of formulas on data fields that are brought into a template.

Inserting an Embedded Document

WordTemplate can insert certain types of documents into docx files by adding the "document(format)" modifier to the merge field, where format is one of the following:

Creating a Grouped and Nested Document

Beginning in version 4.5, the WordTemplate object includes support for nested bookmarks with Office Open XML documents (.docx, .docm, .dotx, and .dotm) in WordWriter Enterprise Edition. Nested bookmarks can be used to format and display hierarchical data.

Using a Database as a Data Source

You can use a database table as a data source for a WordWriter template by passing the SetDataSource method a DataTable, a DataSet, an SqlDataReader, OleDbDataReader or an AdomdDataReader. If the specified data source contains more than one row, SetDataSource will use the first row of the first table as the data source. To import multiple rows from data sources use a repeat block.

Importing from Multiple Data Sources

The main document may include multiples sets of merge fields, where each set of fields binds to a different data source. A SetDataSource call is required for each set of main document merge fields. Only one row of data can be imported to each set of main document merge fields. When you include more than one set of merge fields in the main document, use any of the following SetDataSource methods to set data sources:

Using an Array as a Data Source

The following example generates a Word file from a template that contains the merge fields ProductName, CompanyName, and URL. The WordWriter code gets the values for these fields from an array of objects.

Importing Multiple Rows

Use a repeat block to import multiple rows from a data source. A repeat block is a fragment in the template document - defined by a Word bookmark - that contains merge fields and that will be repeated for each row in a data source. To import multiple rows from a single data source, create a repeat block in the template and, in the WordWriter code, call SetRepeatBlock to bind the repeat block to a data source.

WordTemplate Output Options

After populating your WordWriter template from a data source, call Save to either save the new Word file on the server, or stream it to the browser. WordWriter can:

 

 

 

 

  • No labels