DocumentBuilder Class |
Namespace: Aspose.Words
The DocumentBuilder type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | DocumentBuilder |
Initializes a new instance of this class.
|
![]() ![]() | DocumentBuilder(Document) |
Initializes a new instance of this class.
|
Name | Description | |
---|---|---|
![]() ![]() | Bold |
True if the font is formatted as bold.
|
![]() ![]() | CellFormat |
Returns an object that represents current table cell formatting properties.
|
![]() ![]() | CurrentNode |
Gets the node that is currently selected in this DocumentBuilder.
|
![]() ![]() | CurrentParagraph |
Gets the paragraph that is currently selected in this DocumentBuilder.
|
![]() ![]() | CurrentSection |
Gets the section that is currently selected in this DocumentBuilder.
|
![]() ![]() | CurrentStory |
Gets the story that is currently selected in this DocumentBuilder.
|
![]() ![]() | Document |
Gets or sets the Document object that this object is attached to.
|
![]() ![]() | Font |
Returns an object that represents current font formatting properties.
|
![]() ![]() | IsAtEndOfParagraph |
Returns true if the cursor is at the end of the current paragraph.
|
![]() ![]() | IsAtStartOfParagraph |
Returns true if the cursor is at the beginning of the current paragraph (no text before the cursor).
|
![]() ![]() | Italic |
True if the font is formatted as italic.
|
![]() ![]() | ListFormat |
Returns an object that represents current list formatting properties.
|
![]() ![]() | PageSetup |
Returns an object that represents current page setup and section properties.
|
![]() ![]() | ParagraphFormat |
Returns an object that represents current paragraph formatting properties.
|
![]() ![]() | RowFormat |
Returns an object that represents current table row formatting properties.
|
![]() ![]() | Underline |
Gets/sets underline type for the current font.
|
Name | Description | |
---|---|---|
![]() ![]() | DeleteRow |
Deletes a row from a table.
|
![]() ![]() | EndBookmark |
Marks the current position in the document as a bookmark end.
|
![]() ![]() | EndEditableRange |
Marks the current position in the document as an editable range end.
|
![]() ![]() | EndEditableRange(EditableRangeStart) |
Marks the current position in the document as an editable range end.
|
![]() ![]() | EndRow |
Ends a table row in the document.
|
![]() ![]() | EndTable |
Ends a table in the document.
|
![]() | Equals | (Inherited from Object.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetType | (Inherited from Object.) |
![]() ![]() | InsertBreak |
Inserts a break of the specified type into the document.
|
![]() ![]() | InsertCell |
Inserts a table cell into the document.
|
![]() ![]() | InsertChart(ChartType, Double, Double) |
Inserts an chart object into the document and scales it to the specified size.
|
![]() ![]() | InsertChart(ChartType, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType) |
Inserts an chart object into the document and scales it to the specified size.
|
![]() ![]() | InsertCheckBox(String, Boolean, Int32) |
Inserts a checkbox form field at the current position.
|
![]() ![]() | InsertCheckBox(String, Boolean, Boolean, Int32) |
Inserts a checkbox form field at the current position.
|
![]() ![]() | InsertComboBox |
Inserts a combobox form field at the current position.
|
![]() ![]() | InsertDocument(Document, ImportFormatMode) |
Inserts a document at the cursor position.
|
![]() ![]() | InsertDocument(Document, ImportFormatMode, ImportFormatOptions) |
Inserts a document at the cursor position.
|
![]() ![]() | InsertField(String) |
Inserts a Word field into a document and updates the field result.
|
![]() ![]() | InsertField(String, String) |
Inserts a Word field into a document without updating the field result.
|
![]() ![]() | InsertField(FieldType, Boolean) |
Inserts a Word field into a document and optionally updates the field result.
|
![]() ![]() | InsertFootnote(FootnoteType, String) |
Inserts a footnote or endnote into the document.
|
![]() ![]() | InsertFootnote(FootnoteType, String, String) |
Inserts a footnote or endnote into the document.
|
![]() ![]() | InsertHorizontalRule |
Inserts a horizontal rule shape into the document.
|
![]() ![]() | InsertHtml(String) |
Inserts an HTML string into the document.
|
![]() ![]() | InsertHtml(String, Boolean) |
Inserts an HTML string into the document.
|
![]() ![]() | InsertHyperlink |
Inserts a hyperlink into the document.
|
![]() ![]() | InsertImage(Byte) |
Inserts an image from a byte array into the document. The image is inserted inline and at 100% scale.
|
![]() ![]() | InsertImage(Image) |
Inserts an image from a .NET Image
object into the document. The image is inserted inline and at 100% scale.
|
![]() ![]() | InsertImage(Stream) |
Inserts an image from a stream into the document. The image is inserted inline and at 100% scale.
|
![]() ![]() | InsertImage(String) |
Inserts an image from a file or URL into the document. The image is inserted inline and at 100% scale.
|
![]() ![]() | InsertImage(Byte, Double, Double) |
Inserts an inline image from a byte array into the document and scales it to the specified size.
|
![]() ![]() | InsertImage(Image, Double, Double) |
Inserts an inline image from a .NET Image
object into the document and scales it to the specified size.
|
![]() ![]() | InsertImage(Stream, Double, Double) |
Inserts an inline image from a stream into the document and scales it to the specified size.
|
![]() ![]() | InsertImage(String, Double, Double) |
Inserts an inline image from a file or URL into the document and scales it to the specified size.
|
![]() ![]() | InsertImage(Byte, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType) |
Inserts an image from a byte array at the specified position and size.
|
![]() ![]() | InsertImage(Image, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType) |
Inserts an image from a .NET Image
object at the specified position and size.
|
![]() ![]() | InsertImage(Stream, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType) |
Inserts an image from a stream at the specified position and size.
|
![]() ![]() | InsertImage(String, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType) |
Inserts an image from a file or URL at the specified position and size.
|
![]() ![]() | InsertNode |
Inserts a text level node inside the current paragraph before the cursor.
|
![]() ![]() | InsertOleObject(Stream, String, Boolean, Image) |
Inserts an embedded OLE object from a stream into the document.
|
![]() ![]() | InsertOleObject(String, Boolean, Boolean, Image) |
Inserts an embedded or linked OLE object from a file into the document. Detects OLE object type using file extension.
|
![]() ![]() | InsertOleObject(String, String, Boolean, Boolean, Image) |
Inserts an embedded or linked OLE object from a file into the document. Detects OLE object type using given progID parameter.
|
![]() ![]() | InsertOleObjectAsIcon |
Inserts an embedded or linked OLE object as icon into the document.
Allows to specify icon file and caption. Detects OLE object type using file extension.
|
![]() ![]() | InsertOnlineVideo(String, Double, Double) |
Inserts an online video object into the document and scales it to the specified size.
|
![]() ![]() | InsertOnlineVideo(String, String, Byte, Double, Double) |
Inserts an online video object into the document and scales it to the specified size.
|
![]() ![]() | InsertOnlineVideo(String, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType) |
Inserts an online video object into the document and scales it to the specified size.
|
![]() ![]() | InsertOnlineVideo(String, String, Byte, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType) |
Inserts an online video object into the document and scales it to the specified size.
|
![]() ![]() | InsertParagraph |
Inserts a paragraph break into the document.
|
![]() ![]() | InsertShape(ShapeType, Double, Double) |
Inserts inline shape with specified type and size.
|
![]() ![]() | InsertShape(ShapeType, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType) |
Inserts free-floating shape with specified position, size and text wrap type.
|
![]() ![]() | InsertSignatureLine(SignatureLineOptions) |
Inserts a signature line at the current position.
|
![]() ![]() | InsertSignatureLine(SignatureLineOptions, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, WrapType) |
Inserts a signature line at the specified position.
|
![]() ![]() | InsertStyleSeparator |
Inserts style separator into the document.
|
![]() ![]() | InsertTableOfContents |
Inserts a TOC (table of contents) field into the document.
|
![]() ![]() | InsertTextInput |
Inserts a text form field at the current position.
|
![]() ![]() | MoveTo |
Moves the cursor to an inline node or to the end of a paragraph.
|
![]() ![]() | MoveToBookmark(String) |
Moves the cursor to a bookmark.
|
![]() ![]() | MoveToBookmark(String, Boolean, Boolean) |
Moves the cursor to a bookmark with greater precision.
|
![]() ![]() | MoveToCell |
Moves the cursor to a table cell in the current section.
|
![]() ![]() | MoveToDocumentEnd |
Moves the cursor to the end of the document.
|
![]() ![]() | MoveToDocumentStart |
Moves the cursor to the beginning of the document.
|
![]() ![]() | MoveToField |
Moves the cursor to a field in the document.
|
![]() ![]() | MoveToHeaderFooter |
Moves the cursor to the beginning of a header or footer in the current section.
|
![]() ![]() | MoveToMergeField(String) |
Moves the cursor to a position just beyond the specified merge field and removes the merge field.
|
![]() ![]() | MoveToMergeField(String, Boolean, Boolean) |
Moves the merge field to the specified merge field.
|
![]() ![]() | MoveToParagraph |
Moves the cursor to a paragraph in the current section.
|
![]() ![]() | MoveToSection |
Moves the cursor to the beginning of the body in a specified section.
|
![]() ![]() | PopFont |
Retrieves character formatting previously saved on the stack.
|
![]() ![]() | PushFont |
Saves current character formatting onto the stack.
|
![]() ![]() | StartBookmark |
Marks the current position in the document as a bookmark start.
|
![]() ![]() | StartEditableRange |
Marks the current position in the document as an editable range start.
|
![]() ![]() | StartTable |
Starts a table in the document.
|
![]() | ToString | (Inherited from Object.) |
![]() ![]() | Write |
Inserts a string into the document at the current insert position.
|
![]() ![]() | Writeln |
Inserts a paragraph break into the document.
|
![]() ![]() | Writeln(String) |
Inserts a string and a paragraph break into the document.
|
DocumentBuilder makes the process of building a Document easier. Document is a composite object consisting of a tree of nodes and while inserting content nodes directly into the tree is possible, it requires good understanding of the tree structure. DocumentBuilder is a "facade" for the complex structure of Document and allows to insert content and formatting quickly and easily.
Create a DocumentBuilder and associate it with a Document.
The DocumentBuilder has an internal cursor where the text will be inserted when you call Write(String), Writeln(String), InsertBreak(BreakType) and other methods. You can navigate the DocumentBuilder cursor to a different location in a document using various MoveToXXX methods.
Use the Font property to specify character formatting that will apply to all text inserted from the current position in the document onwards.
Use the ParagraphFormat property to specify paragraph formatting for the current and all paragraphs that will be inserted.
Use the PageSetup property to specify page and section properties for the current section and all section that will be inserted.
Use the CellFormat and RowFormat properties to specify formatting properties for table cells and rows. User the InsertCell and EndRow methods to build a table.
Note that Font, ParagraphFormat and PageSetup properties are updated whenever you navigate to a different place in the document to reflect formatting properties available at the new location.
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // We call this method to start building the table builder.StartTable(); builder.InsertCell(); builder.Write("Row 1, Cell 1 Content."); // Build the second cell builder.InsertCell(); builder.Write("Row 1, Cell 2 Content."); // Call the following method to end the row and start a new row builder.EndRow(); // Build the first cell of the second row builder.InsertCell(); builder.Write("Row 2, Cell 1 Content"); // Build the second cell. builder.InsertCell(); builder.Write("Row 2, Cell 2 Content."); builder.EndRow(); // Signal that we have finished building the table builder.EndTable(); // Save the document to disk doc.Save(ArtifactsDir + "DocumentBuilder.CreateSimpleTable.doc");
// Create a blank document Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Specify that we want headers and footers different for first, even and odd pages builder.PageSetup.DifferentFirstPageHeaderFooter = true; builder.PageSetup.OddAndEvenPagesHeaderFooter = true; // Create the headers builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst); builder.Write("Header First"); builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven); builder.Write("Header Even"); builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary); builder.Write("Header Odd"); // Create three pages in the document builder.MoveToSection(0); builder.Writeln("Page1"); builder.InsertBreak(BreakType.PageBreak); builder.Writeln("Page2"); builder.InsertBreak(BreakType.PageBreak); builder.Writeln("Page3"); doc.Save(ArtifactsDir + "DocumentBuilder.HeadersAndFooters.doc");
DocumentBuilder builder = new DocumentBuilder(); // Start building a table builder.StartTable(); // Set the appropriate paragraph, cell, and row formatting. The formatting properties are preserved // until they are explicitly modified so there's no need to set them for each row or cell builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; builder.CellFormat.ClearFormatting(); builder.CellFormat.Width = 150; builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; builder.CellFormat.Shading.BackgroundPatternColor = Color.GreenYellow; builder.CellFormat.WrapText = false; builder.CellFormat.FitText = true; builder.RowFormat.ClearFormatting(); builder.RowFormat.HeightRule = HeightRule.Exactly; builder.RowFormat.Height = 50; builder.RowFormat.Borders.LineStyle = LineStyle.Engrave3D; builder.RowFormat.Borders.Color = Color.Orange; builder.InsertCell(); builder.Write("Row 1, Col 1"); builder.InsertCell(); builder.Write("Row 1, Col 2"); builder.EndRow(); // Remove the shading (clear background) builder.CellFormat.Shading.ClearFormatting(); builder.InsertCell(); builder.Write("Row 2, Col 1"); builder.InsertCell(); builder.Write("Row 2, Col 2"); builder.EndRow(); builder.InsertCell(); // Make the row height bigger so that a vertically oriented text could fit into cells builder.RowFormat.Height = 150; builder.CellFormat.Orientation = TextOrientation.Upward; builder.Write("Row 3, Col 1"); builder.InsertCell(); builder.CellFormat.Orientation = TextOrientation.Downward; builder.Write("Row 3, Col 2"); builder.EndRow(); builder.EndTable(); builder.Document.Save(ArtifactsDir + "DocumentBuilder.InsertTable.docx");