Run class
Run class
Represents a run of characters with the same font formatting. To learn more, visit the Programming with Documents documentation article.
Remarks
All text of the document is stored in runs of text.
Run can only be a child of Paragraph or inline StructuredDocumentTag.
Inheritance: Run → Inline → Node
Constructors
Name | Description |
---|---|
Run(doc) | Initializes a new instance of the Run class. |
Run(doc, text) | Initializes a new instance of the Run class. |
Properties
Name | Description |
---|---|
customNodeId | Specifies custom node identifier. (Inherited from Node) |
document | Gets the document to which this node belongs. (Inherited from Node) |
font | Provides access to the font formatting of this object. (Inherited from Inline) |
isComposite | Returns true if this node can contain other nodes.(Inherited from Node) |
isDeleteRevision | Returns true if this object was deleted in Microsoft Word while change tracking was enabled. (Inherited from Inline) |
isFormatRevision | Returns true if formatting of the object was changed in Microsoft Word while change tracking was enabled. (Inherited from Inline) |
isInsertRevision | Returns true if this object was inserted in Microsoft Word while change tracking was enabled. (Inherited from Inline) |
isMoveFromRevision | Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled.(Inherited from Inline) |
isMoveToRevision | Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled.(Inherited from Inline) |
isPhoneticGuide | Gets a boolean value indicating either the run is a phonetic guide. |
nextSibling | Gets the node immediately following this node. (Inherited from Node) |
nodeType | Returns NodeType.Run. |
parentNode | Gets the immediate parent of this node. (Inherited from Node) |
parentParagraph | Retrieves the parent Paragraph of this node. (Inherited from Inline) |
phoneticGuide | Gets a Run.phoneticGuide object. |
previousSibling | Gets the node immediately preceding this node. (Inherited from Node) |
range | Returns a Range object that represents the portion of a document that is contained in this node. (Inherited from Node) |
text | Gets or sets the text of the run. |
Methods
Name | Description |
---|---|
asBody() | Cast node to Body. (Inherited from Node) |
asBookmarkEnd() | Cast node to BookmarkEnd. (Inherited from Node) |
asBookmarkStart() | Cast node to BookmarkStart. (Inherited from Node) |
asBuildingBlock() | Cast node to BuildingBlock. (Inherited from Node) |
asCell() | Cast node to Cell. (Inherited from Node) |
asComment() | Cast node to Comment. (Inherited from Node) |
asCommentRangeEnd() | Cast node to CommentRangeEnd. (Inherited from Node) |
asCommentRangeStart() | Cast node to CommentRangeStart. (Inherited from Node) |
asCompositeNode() | Cast node to CompositeNode. (Inherited from Node) |
asDocument() | Cast node to Node.document. (Inherited from Node) |
asEditableRangeEnd() | Cast node to EditableRangeEnd. (Inherited from Node) |
asEditableRangeStart() | Cast node to EditableRangeStart. (Inherited from Node) |
asFieldEnd() | Cast node to FieldEnd. (Inherited from Node) |
asFieldSeparator() | Cast node to FieldSeparator. (Inherited from Node) |
asFieldStart() | Cast node to FieldStart. (Inherited from Node) |
asFootnote() | Cast node to Footnote. (Inherited from Node) |
asFormField() | Cast node to FormField. (Inherited from Node) |
asGlossaryDocument() | Cast node to GlossaryDocument. (Inherited from Node) |
asGroupShape() | Cast node to GroupShape. (Inherited from Node) |
asHeaderFooter() | Cast node to HeaderFooter. (Inherited from Node) |
asOfficeMath() | Cast node to OfficeMath. (Inherited from Node) |
asParagraph() | Cast node to Paragraph. (Inherited from Node) |
asRow() | Cast node to Row. (Inherited from Node) |
asRun() | Cast node to Run. (Inherited from Node) |
asSection() | Cast node to Section. (Inherited from Node) |
asShape() | Cast node to Shape. (Inherited from Node) |
asSmartTag() | Cast node to SmartTag. (Inherited from Node) |
asSpecialChar() | Cast node to SpecialChar. (Inherited from Node) |
asStructuredDocumentTag() | Cast node to StructuredDocumentTag. (Inherited from Node) |
asStructuredDocumentTagRangeEnd() | Cast node to StructuredDocumentTagRangeEnd. (Inherited from Node) |
asStructuredDocumentTagRangeStart() | Cast node to StructuredDocumentTagRangeStart. (Inherited from Node) |
asSubDocument() | Cast node to SubDocument. (Inherited from Node) |
asTable() | Cast node to Table. (Inherited from Node) |
clone(isCloneChildren) | Creates a duplicate of the node. (Inherited from Node) |
getAncestor(ancestorType) | Gets the first ancestor of the specified NodeType. (Inherited from Node) |
getText() | Gets the text of the run. |
nextPreOrder(rootNode) | Gets next node according to the pre-order tree traversal algorithm. (Inherited from Node) |
nodeTypeToString(nodeType) | A utility method that converts a node type enum value into a user friendly string. (Inherited from Node) |
previousPreOrder(rootNode) | Gets the previous node according to the pre-order tree traversal algorithm. (Inherited from Node) |
referenceEquals(other) | (Inherited from Node) |
remove() | Removes itself from the parent. (Inherited from Node) |
toString(saveFormat) | Exports the content of the node into a string in the specified format. (Inherited from Node) |
toString(saveOptions) | Exports the content of the node into a string using the specified save options. (Inherited from Node) |
Examples
Shows how to construct an Aspose.words document by hand.
let doc = new aw.Document();
// A blank document contains one section, one body and one paragraph.
// Call the "RemoveAllChildren" method to remove all those nodes,
// and end up with a document node with no children.
doc.removeAllChildren();
// This document now has no composite child nodes that we can add content to.
// If we wish to edit it, we will need to repopulate its node collection.
// First, create a new section, and then append it as a child to the root document node.
let section = new aw.Section(doc);
doc.appendChild(section);
// Set some page setup properties for the section.
section.pageSetup.sectionStart = aw.SectionStart.NewPage;
section.pageSetup.paperSize = aw.PaperSize.Letter;
// A section needs a body, which will contain and display all its contents
// on the page between the section's header and footer.
let body = new aw.Body(doc);
section.appendChild(body);
// Create a paragraph, set some formatting properties, and then append it as a child to the body.
let para = new aw.Paragraph(doc);
para.paragraphFormat.styleName = "Heading 1";
para.paragraphFormat.alignment = aw.ParagraphAlignment.Center;
body.appendChild(para);
// Finally, add some content to do the document. Create a run,
// set its appearance and contents, and then append it as a child to the paragraph.
let run = new aw.Run(doc);
run.text = "Hello World!";
run.font.color = "#FF0000";
para.appendChild(run);
expect(doc.getText().trim()).toEqual("Hello World!");
doc.save(base.artifactsDir + "Section.CreateManually.docx");
Shows how to format a run of text using its font property.
let doc = new aw.Document();
let run = new aw.Run(doc, "Hello world!");
let font = run.font;
font.name = "Courier New";
font.size = 36;
font.highlightColor = "#FFFF00";
doc.firstSection.body.firstParagraph.appendChild(run);
doc.save(base.artifactsDir + "Font.CreateFormattedRun.docx");
Shows how to add, update and delete child nodes in a CompositeNode’s collection of children.
let doc = new aw.Document();
// An empty document, by default, has one paragraph.
expect(doc.firstSection.body.paragraphs.count).toEqual(1);
// Composite nodes such as our paragraph can contain other composite and inline nodes as children.
let paragraph = doc.firstSection.body.firstParagraph;
let paragraphText = new aw.Run(doc, "Initial text. ");
paragraph.appendChild(paragraphText);
// Create three more run nodes.
let run1 = new aw.Run(doc, "Run 1. ");
let run2 = new aw.Run(doc, "Run 2. ");
let run3 = new aw.Run(doc, "Run 3. ");
// The document body will not display these runs until we insert them into a composite node
// that itself is a part of the document's node tree, as we did with the first run.
// We can determine where the text contents of nodes that we insert
// appears in the document by specifying an insertion location relative to another node in the paragraph.
expect(paragraph.getText().trim()).toEqual("Initial text.");
// Insert the second run into the paragraph in front of the initial run.
paragraph.insertBefore(run2, paragraphText);
expect(paragraph.getText().trim()).toEqual("Run 2. Initial text.");
// Insert the third run after the initial run.
paragraph.insertAfter(run3, paragraphText);
expect(paragraph.getText().trim()).toEqual("Run 2. Initial text. Run 3.");
// Insert the first run to the start of the paragraph's child nodes collection.
paragraph.prependChild(run1);
expect(paragraph.getText().trim()).toEqual("Run 1. Run 2. Initial text. Run 3.");
expect(paragraph.getChildNodes(aw.NodeType.Any, true).count).toEqual(4);
// We can modify the contents of the run by editing and deleting existing child nodes.
//paragraph.getChildNodes(aw.NodeType.Run, true).toArray().at(1).text = "Updated run 2. ";
//paragraph.getChildNodes(aw.NodeType.Run, true).remove(paragraphText);
paragraph.getChildNodes(aw.NodeType.Run, true).toArray().at(1).asRun().text = "Updated run 2. ";
paragraph.getChildNodes(aw.NodeType.Run, true).remove(paragraphText);
expect(paragraph.getText().trim()).toEqual("Run 1. Updated run 2. Run 3.");
expect(paragraph.getChildNodes(aw.NodeType.Any, true).count).toEqual(3);
See Also
- module Aspose.Words
- class Inline