Document
Overview
Document is a class in Aspose.Words FOSS for .NET.
Inherits from: DocumentBase, ISectionAttrSource, IWatermarkProvider.
The Document class constructors let developers create a new empty document or load an existing one from a file path, stream, or with custom load options.
This class provides 63 methods for working with Document objects in .NET programs.
Available methods include: Accept, AcceptAllRevisions, AcceptEnd, AcceptStart, AppendChild, AppendDocument, Cleanup, Clone, CopyStylesFromTemplate, CreateNavigator, Document, EnsureMinimum, and 36 additional methods.
All public members are accessible to any .NET application after installing the Aspose.Words FOSS for .NET package.
Properties: AttachedTemplate, AutomaticallyUpdateStyles, BackgroundShape, Bibliography, BuiltInDocumentProperties, CompatibilityOptions, and 62 more.
Properties
| Name | Type | Access | Description |
|---|---|---|---|
AttachedTemplate | string | Read/Write | Gets or sets the full path of the template attached to the document. |
AutomaticallyUpdateStyles | bool | Read/Write | Gets or sets a flag indicating whether the styles in the document are updated to match the styles in the attached template each time the document is opened in MS Word. |
ShadeFormData | bool | Read/Write | Specifies whether to turn on the gray shading on form fields. |
TrackRevisions | bool | Read/Write | True if changes are tracked when this document is edited in Microsoft Word. |
ShowGrammaticalErrors | bool | Read/Write | Specifies whether to display grammar errors in this document. |
ShowSpellingErrors | bool | Read/Write | Specifies whether to display spelling errors in this document. |
SpellingChecked | bool | Read/Write | Returns true if the document has been checked for spelling. |
GrammarChecked | bool | Read/Write | Returns true if the document has been checked for grammar. |
PunctuationKerning | bool | Read/Write | Specifies whether kerning applies to both Latin text and punctuation. |
NodeType | NodeType | Read | Returns Document. |
BuiltInDocumentProperties | BuiltInDocumentProperties | Read | Returns a collection that represents all the built-in document properties of the document. |
WebExtensionTaskPanes | TaskPaneCollection | Read | Returns a collection that represents a list of task pane add-ins. |
CustomDocumentProperties | CustomDocumentProperties | Read | Returns a collection that represents all the custom document properties of the document. |
ProtectionType | ProtectionType | Read | Gets the currently active document protection type. |
Sections | SectionCollection | Read | Returns a collection that represents all sections in the document. |
FirstSection | Section | Read | Gets the first section in the document. |
LastSection | Section | Read | Gets the last section in the document. |
ViewOptions | ViewOptions | Read | Provides options to control how the document is displayed in Microsoft Word. |
WriteProtection | WriteProtection | Read | Provides access to the document write protection options. |
CompatibilityOptions | CompatibilityOptions | Read | Provides access to document compatibility options (that is, the user preferences entered on the Compatibility tab of the Options dialog in Word). |
MailMergeSettings | MailMergeSettings | Read/Write | Gets or sets the object that contains all of the mail merge information for a document. |
HyphenationOptions | HyphenationOptions | Read | Provides access to document hyphenation options. |
HasRevisions | bool | Read | Returns true if the document has any tracked changes. |
HasMacros | bool | Read | Returns true if the document has a VBA project (macros). |
Watermark | Watermark | Read | Provides access to the document watermark. |
VersionsCount | int | Read | Gets the number of document versions that was stored in the DOC document. |
DefaultTabStop | double | Read/Write | Gets or sets the interval (in points) between the default tab stops. |
Theme | Theme | Read | Gets the Theme object for this document. |
CustomXmlParts | CustomXmlPartCollection | Read/Write | Gets or sets the collection of Custom XML Data Storage Parts. |
PackageCustomParts | CustomPartCollection | Read/Write | Gets or sets the collection of custom parts (arbitrary content) that are linked to the OOXML package using “unknown relationships”. |
Variables | VariableCollection | Read | Returns the collection of variables added to a document or template. |
GlossaryDocument | GlossaryDocument | Read/Write | Gets or sets the glossary document within this document or template. |
OriginalFileName | string | Read | Gets the original file name of the document. |
OriginalLoadFormat | LoadFormat | Read | Gets the format of the original document that was loaded into this object. |
Compliance | OoxmlCompliance | Read | Gets the OOXML compliance version determined from the loaded document content. |
DigitalSignatures | DigitalSignatureCollection | Read | Gets the collection of digital signatures for this document and their validation results. |
FontSettings | FontSettings | Read/Write | Gets or sets document font settings. |
Bibliography | Bibliography.Bibliography | Read | Gets the Bibliography object that represents the list of sources available in the document. |
Frameset | Frameset | Read | Returns a Frameset instance if this document represents a frames page. |
IncludeTextboxesFootnotesEndnotesInStat | bool | Read/Write | Specifies whether to include textboxes, footnotes and endnotes in word count statistics. |
Revisions | RevisionCollection | Read | Gets a collection of revisions (tracked changes) that exist in this document. |
RevisionsView | RevisionsView | Read/Write | Gets or sets a value indicating whether to work with the original or revised version of a document. |
JustificationMode | JustificationMode | Read/Write | Gets or sets the character spacing adjustment of a document. |
FootnoteOptions | FootnoteOptions | Read | Provides options that control numbering and positioning of footnotes in this document. |
EndnoteOptions | EndnoteOptions | Read | Provides options that control numbering and positioning of endnotes in this document. |
FieldOptions | FieldOptions | Read | Gets a FieldOptions object that represents options to control field handling in the document. |
RemovePersonalInformation | bool | Read/Write | Gets or sets a flag indicating that Microsoft Word will remove all user information from comments, revisions and document properties upon saving the document. |
VbaProject | VbaProject | Read/Write | Gets or sets a VbaProject. |
Document | DocumentBase | Read | Gets this instance. |
NodeChangingCallback | INodeChangingCallback | Read/Write | Called when a node is inserted or removed in the document. |
ResourceLoadingCallback | IResourceLoadingCallback | Read/Write | Allows to control how external resources are loaded. |
FontInfos | FontInfoCollection | Read | Provides access to properties of fonts used in this document. |
Styles | StyleCollection | Read | Returns a collection of styles defined in the document. |
Lists | ListCollection | Read | Provides access to the list formatting used in the document. |
WarningCallback | IWarningCallback | Read/Write | Called during various document processing procedures when an issue is detected that might result in data or formatting fidelity loss. |
FootnoteSeparators | FootnoteSeparatorCollection | Read | Provides access to the footnote/endnote separators defined in the document. |
BackgroundShape | Shape | Read/Write | Gets or sets the background shape of the document. |
PageColor | Color | Read/Write | Gets or sets the page color of the document. |
IsComposite | bool | Read | Returns true as this node can have child nodes. |
HasChildNodes | bool | Read | Returns true if this node has any child nodes. |
FirstChild | Node | Read | Gets the first child of the node. |
LastChild | Node | Read | Gets the last child of the node. |
Count | int | Read | Gets the number of immediate children of this node. |
ParentNode | CompositeNode | Read | Gets the immediate parent of this node. |
PreviousSibling | Node | Read | Gets the node immediately preceding this node. |
NextSibling | Node | Read | Gets the node immediately following this node. |
Range | Range | Read | Returns a Range object that represents the portion of a document that is contained in this node. |
CustomNodeId | int | Read/Write | Specifies custom node identifier. |
Methods
| Signature | Description |
|---|---|
Document() | Creates or loads a document. |
Document(fileName: string) | Opens an existing document from a file. |
Document(fileName: string, loadOptions: LoadOptions) | Opens an existing document from a file. |
Document(stream: Stream) | Calls Document(stream) on this Document instance. |
Document(stream: Stream, loadOptions: LoadOptions) | Calls Document(stream, loadOptions) on this Document instance. |
Clone() | Performs a deep copy of the Document. |
Accept(visitor: DocumentVisitor) | Calls VisitDocumentStart, then calls Accept for all child nodes of the document and calls VisitDocumentEnd at the end. |
AcceptStart(visitor: DocumentVisitor) | Accepts a visitor for visiting the start of the document. |
AcceptEnd(visitor: DocumentVisitor) | Accepts a visitor for visiting the end of the document. |
AppendDocument(srcDoc: Document, importFormatMode: ImportFormatMode) | Appends the specified document to the end of this document. |
AppendDocument(srcDoc: Document, importFormatMode: ImportFormatMode, importFormatOptions: ImportFormatOptions) | Appends the specified document to the end of this document. |
Save(fileName: string) | Saves the document. |
Save(fileName: string, saveFormat: SaveFormat) | Saves the document to a file in the specified format. |
Save(fileName: string, saveOptions: SaveOptions) | Saves the document to a file using the specified save options. |
Save(stream: Stream, saveFormat: SaveFormat) | Overloads enable saving a document to a file name or a stream, optionally specifying a save format or detailed save options |
Save(stream: Stream, saveOptions: SaveOptions) | Calls Save(stream, saveOptions) on this Document instance. |
Save(response: HttpResponse, fileName: string, contentDisposition: ContentDisposition, saveOptions: SaveOptions) | Sends the document to the client browser. |
EnsureMinimum() | If the document contains no sections, creates one section with one paragraph. |
AcceptAllRevisions() | Accepts all tracked changes in the document. |
Protect(type: ProtectionType) | Protects the document from changes. |
Protect(type: ProtectionType, password: string) | Protects the document from changes and optionally sets a protection password. |
Unprotect() | Removes protection from the document. |
Unprotect(password: string) | Removes protection from the document if a correct password is specified. |
UpdateTableLayout() | Implements an earlier approach to table column widths re-calculation that has known issues. |
UpdateListLabels() | Updates list labels for all list items in the document. |
UpdateActualReferenceMarks() | Updates the ActualReferenceMark property of all footnotes and endnotes in the document. |
RemoveMacros() | Removes all macros (the VBA project) as well as toolbars and command customizations from the document. |
UpdateFields() | Updates the values of fields in the whole document. |
UnlinkFields() | Unlinks fields in the whole document. |
NormalizeFieldTypes() | Changes field type values FieldType of FieldStart, FieldSeparator, FieldEnd in the whole document so that they correspond to the field types contained in the field codes. |
JoinRunsWithSameFormatting() | Joins runs with same formatting in all paragraphs of the document. |
ExpandTableStylesToDirectFormatting() | Converts formatting specified in table styles into direct formatting on tables in the document. |
Cleanup() | Cleans unused styles and lists from the document. |
Cleanup(options: CleanupOptions) | Cleans unused styles and lists from the document depending on given CleanupOptions. |
RemoveExternalSchemaReferences() | Removes external XML schema references from this document. |
StartTrackRevisions(author: string, dateTime: DateTime) | Starts automatically marking all further changes you make to the document programmatically as revision changes. |
StartTrackRevisions(author: string) | Starts automatically marking all further changes you make to the document programmatically as revision changes. |
StopTrackRevisions() | Stops automatic marking of document changes as revisions. |
CopyStylesFromTemplate(template: string) | Copies styles from the specified template to a document. |
CopyStylesFromTemplate(template: Document) | Copies styles from the specified template to a document. |
ImportNode(srcNode: Node, isImportChildren: bool) | Imports a node from another document to the current document. |
GetText() | Gets the text of this node and of all its children. |
GetChildNodes(nodeType: NodeType, isDeep: bool) | Returns a collection of child nodes that match the specified type. |
GetChild(nodeType: NodeType, index: int, isDeep: bool) | Returns an Nth child node that matches the specified type. |
SelectNodes(xpath: string) | Selects a list of nodes matching the XPath expression. |
SelectSingleNode(xpath: string) | Selects the first Node that matches the XPath expression. |
GetEnumerator() | Provides support for the for each style iteration over the child nodes of this node. |
AppendChild(newChild: T) | Adds the specified node to the end of the list of child nodes for this node. |
PrependChild(newChild: T) | Adds the specified node to the beginning of the list of child nodes for this node. |
InsertAfter(newChild: T, refChild: Node) | Inserts the specified node immediately after the specified reference node. |
InsertBefore(newChild: T, refChild: Node) | Inserts the specified node immediately before the specified reference node. |
RemoveChild(oldChild: T) | Removes the specified child node. |
RemoveAllChildren() | Removes all the child nodes of the current node. |
RemoveSmartTags() | Removes all SmartTag descendant nodes of the current node. |
IndexOf(child: Node) | Returns the index of the specified child node in the child node array. |
CreateNavigator() | Creates navigator which can be used to traverse and read nodes. |
GetAncestor(ancestorType: Type) | Gets the first ancestor of the specified object type. |
GetAncestorOf() | Calls GetAncestorOf on this Document instance. |
Remove() | Removes itself from the parent. |
NextPreOrder(rootNode: Node) | Gets next node according to the pre-order tree traversal algorithm. |
PreviousPreOrder(rootNode: Node) | Gets the previous node according to the pre-order tree traversal algorithm. |
ToString(saveFormat: SaveFormat) | Exports the content of the node into a string in the specified format. |
NodeTypeToString(nodeType: NodeType) | A utility method that converts a node type enum value into a user friendly string. |