Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
The DocumentBuilder
is used to modify documents. This article explains and describes how to perform a number of tasks:
Simply pass the string of text you need to insert into the document to the DocumentBuilder.Write
method. Text formatting is determined by the Font
property. This object contains different font attributes (font name, font size, colour, and so on). Some important font attributes are also represented by DocumentBuilder properties to allow you to access them directly. These are Boolean properties Font.Bold
, Font.Italic
, and Font.Underline
.
Note that the character formatting you set will apply to all text inserted from the current position in the document onwards.
Below example Inserts formatted text using DocumentBuilder.
DocumentBuilder.Writeln
inserts a string of text into the document as well but in addition, it adds a paragraph break. Current font formatting is also specified by the DocumentBuilder.Font
property and current paragraph formatting is determined by the DocumentBuilder.ParagraphFormat
property. Below example shows how to insert a paragraph into the document.
The basic algorithm for creating a table using DocumentBuilder is simple:
DocumentBuilder.StartTable
.DocumentBuilder.InsertCell
. This automatically starts a new row. If needed, use the DocumentBuilder.CellFormat
property to specify cell formatting.DocumentBuilder
methods.DocumentBuilder.EndRow
to end the current row. If needed, use DocumentBuilder.RowFormat
property to specify row formatting.DocumentBuilder.EndTable
to finish the table building. The appropriate DocumentBuilder table creation methods are described below.Calling DocumentBuilder.StartTable
is the first step in building a table. It can be also called inside a cell, in which case it starts a nested table. The next method to call is DocumentBuilder.InsertCell
.
After you call DocumentBuilder->InsertCell
, a new cell is created and any content you add using other methods of the DocumentBuilder
class will be added to the current cell. To start a new cell in the same row, call DocumentBuilder->InsertCell
again. Use the DocumentBuilder.CellFormat
property to specify cell formatting. It returns a CellFormat
object that represents all formatting for a table cell.
Call DocumentBuilder.EndRow
to finish the current row. If you call DocumentBuilder->InsertCell
immediately after that, then the table continues on a new row.
Use the DocumentBuilder.RowFormat
property to specify row formatting. It returns a RowFormat
object that represents all formatting for a table row.
Call DocumentBuilder.EndTable
to finish the current table. This method should be called only once after DocumentBuilder->EndRow
was called. When called, DocumentBuilder.EndTable
moves the cursor out of the current cell to a position just after the table. The following example demonstrates how to build a formatted table that contains 2 rows and 2 columns.
If you want to explicitly start a new line, paragraph, column, section, or page, call DocumentBuilder.InsertBreak
. Pass to this method the type of the break you need to insert that is represented by the BreakType
enumeration. Below example shows how to insert page breaks into a document.
DocumentBuilder provides several overloads of the DocumentBuilder->InsertImage
method that allows you to insert an inline or floating image. If the image is an EMF or WMF metafile, it will be inserted into the document in metafile format. All other images will be stored in PNG format. The DocumentBuilder->InsertImage
method can use images from different sources:
URL
by passing a string parameter DocumentBuilder->InsertImage
.Stream
parameter DocumentBuilder->InsertImage
.DocumentBuilder->InsertImage
.DocumentBuilder.InsertImage
.For each of the DocumentBuilder->InsertImage
methods, there are further overloads which allow you to insert an image with the following options:DocumentBuilder->InsertImage
.DocumentBuilder.InsertImage
. Furthermore the DocumentBuilder->InsertImage
method returns a Shape
object that was just created and inserted so you can further modify properties of the Shape.Pass a single string representing a file that contains the image to DocumentBuilder->InsertImage
to insert the image into the document as an inline graphics. Below example shows how to insert an inline image at the cursor position into a document.
This example inserts a floating image from a file or URL
at a specified position and size.
To insert a bookmark into the document, you should do the following:
DocumentBuilder->StartBookmark
passing it the desired name of the bookmark.DocumentBuilder.EndBookmark
passing it the same name that you used with DocumentBuilder->StartBookmark.DocumentBuilder->StartBookmark
and DocumentBuilder->EndBookmark
with the same bookmark name.Below example shows how to insert a bookmark into a document using a document builder.
Form
FieldForm fields are a particular case of Word fields that allows “interaction” with the user. Form fields in Microsoft Word include textbox, combo box and checkbox.DocumentBuilder provides special methods to insert each type of form field into the document: DocumentBuilder.InsertTextInput
, DocumentBuilder->InsertCheckBox
, and DocumentBuilder.InsertComboBox
. Note that if you specify a name for the form field, then a bookmark is automatically created with the same name.
DocumentBuilder.InsertTextInput
to insert a textbox into the document. Below example shows how to insert a text input form field into a document.
Call DocumentBuilder.InsertCheckBox
to insert a checkbox into the document. Below example shows how to insert a checkbox form field into a document.
Call DocumentBuilder.InsertComboBox
to insert a combo box into the document. Below example shows how to insert a combo box form field into a document.
Customers can specify Locale at field level now and can achieve better control. Locale Ids can be associated with each field inside the DocumentBuilder. The examples below illustrate how to make use of this option.
Use DocumentBuilder.InsertHyperlink
to insert a hyperlink into the document. This method accepts three parameters: text of the link to be displayed in the document, link destination (URL or a name of a bookmark inside the document), and a boolean parameter that should be true if the URL
is a name of a bookmark inside the document.DocumentBuilder.InsertHyperlink internally calls DocumentBuilder.InsertField
.The method always adds apostrophes at the beginning and end of the URL. Note that you need to specify font formatting for the hyperlink display text explicitly using the Font
property. Below example inserts a hyperlink into a document using DocumentBuilder.
If you want Ole Object call DocumentBuilder.InsertOleObject
. Pass to this method the ProgId
explicitly with other parameters. Below example shows how to insert Ole Object into a document.
OLE package is a legacy and “undocumented” way to store embedded object if OLE handler is unknown. Early Windows versions such as Windows 3.1, 95 and 98 had Packager.exe application which could be used to embed any type of data into the document. Now, this application is excluded from Windows but MS Word and other applications still use it to embed data if OLE handler is missing or unknown. OlePackage class allows to access OLE Package properties. Below example shows how to set file name, extension and display name for OLE Package.
You can easily insert an HTML string that contains an HTML fragment or whole HTML document into the Word document. Just pass this string to the DocumentBuilder->InsertHtml
method. One of the useful implementations of the method is storing an HTML string in a database and inserting it into the document during Mail Merge to get the formatted content added instead of building it using various methods of the document builder. Below example shows inserts HTML into a document using DocumentBuilder.
Below code example shows how to insert horizontal rule shape into a document using DocumentBuilder->InsertHorizontalRule
method.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.