Aspose::Words::Document class

Document class

Represents a Word document. To learn more, visit the Working with Document documentation article.

class Document : public Aspose::Words::DocumentBase,
                 public Aspose::Words::ISectionAttrSource,
                 public Aspose::Words::IWatermarkProvider

Methods

MethodDescription
Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>) overrideAccepts a visitor.
AcceptAllRevisions()Accepts all tracked changes in the document.
AcceptEnd(System::SharedPtr<Aspose::Words::DocumentVisitor>) override
AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>) override
AppendChild(T)
AppendDocument(const System::SharedPtr<Aspose::Words::Document>&, Aspose::Words::ImportFormatMode)Appends the specified document to the end of this document.
AppendDocument(const System::SharedPtr<Aspose::Words::Document>&, Aspose::Words::ImportFormatMode, const System::SharedPtr<Aspose::Words::ImportFormatOptions>&)Appends the specified document to the end of this document.
Cleanup()Cleans unused styles and lists from the document.
Cleanup(const System::SharedPtr<Aspose::Words::CleanupOptions>&)Cleans unused styles and lists from the document depending on given CleanupOptions.
Clone()Performs a deep copy of the Document.
Clone(bool)Creates a duplicate of the node.
Compare(const System::SharedPtr<Aspose::Words::Document>&, const System::String&, System::DateTime)Compares this document with another document producing changes as number of edit and format revisions Revision.
Compare(const System::SharedPtr<Aspose::Words::Document>&, const System::String&, System::DateTime, const System::SharedPtr<Aspose::Words::Comparing::CompareOptions>&)Compares this document with another document producing changes as a number of edit and format revisions Revision. Allows to specify comparison options using CompareOptions.
CopyStylesFromTemplate(const System::String&)Copies styles from the specified template to a document.
CopyStylesFromTemplate(const System::SharedPtr<Aspose::Words::Document>&)Copies styles from the specified template to a document.
Document()Creates a blank Word document.
Document(const System::String&)Opens an existing document from a file. Automatically detects the file format.
Document(const System::String&, const System::SharedPtr<Aspose::Words::Loading::LoadOptions>&)Opens an existing document from a file. Allows to specify additional options such as an encryption password.
Document(const System::SharedPtr<System::IO::Stream>&)Opens an existing document from a stream. Automatically detects the file format.
Document(const System::SharedPtr<System::IO::Stream>&, const System::SharedPtr<Aspose::Words::Loading::LoadOptions>&)Opens an existing document from a stream. Allows to specify additional options such as an encryption password.
Document(std::istream&)
Document(std::istream&, const System::SharedPtr<Aspose::Words::Loading::LoadOptions>&)
EnsureMinimum()If the document contains no sections, creates one section with one paragraph.
ExpandTableStylesToDirectFormatting()Converts formatting specified in table styles into direct formatting on tables in the document.
ExtractPages(int32_t, int32_t)Returns the Document object representing specified range of pages.
get_AttachedTemplate()Gets or sets the full path of the template attached to the document.
get_AutomaticallyUpdateStyles()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.
get_BackgroundShape() constGets or sets the background shape of the document. Can be null.
get_Bibliography()
get_BuiltInDocumentProperties() constReturns a collection that represents all the built-in document properties of the document.
get_CompatibilityOptions()Provides access to document compatibility options (that is, the user preferences entered on the Compatibility tab of the Options dialog in Word).
get_Compliance()Gets the OOXML compliance version determined from the loaded document content. Makes sense only for OOXML documents.
get_Count()Gets the number of immediate children of this node.
get_CustomDocumentProperties()Returns a collection that represents all the custom document properties of the document.
get_CustomNodeId() constSpecifies custom node identifier.
get_CustomXmlParts() constGets or sets the collection of Custom XML Data Storage Parts.
get_DefaultTabStop()Gets or sets the interval (in points) between the default tab stops.
get_DigitalSignatures() constGets the collection of digital signatures for this document and their validation results.
get_Document() const overrideGets this instance.
get_EndnoteOptions()Provides options that control numbering and positioning of endnotes in this document.
get_FieldOptions()Gets a FieldOptions object that represents options to control field handling in the document.
get_FirstChild() constGets the first child of the node.
get_FirstSection()Gets the first section in the document.
get_FontInfos() constProvides access to properties of fonts used in this document.
get_FontSettings() constGets or sets document font settings.
get_FootnoteOptions()Provides options that control numbering and positioning of footnotes in this document.
get_Frameset() constReturns a Frameset instance if this document represents a frames page.
get_GlossaryDocument() constGets or sets the glossary document within this document or template. A glossary document is a storage for AutoText, AutoCorrect and Building Block entries defined in a document.
get_GrammarChecked()Returns true if the document has been checked for grammar.
get_HasChildNodes()Returns true if this node has any child nodes.
get_HasMacros()Returns true if the document has a VBA project (macros).
get_HasRevisions()Returns true if the document has any tracked changes.
get_HyphenationOptions()Provides access to document hyphenation options.
get_IncludeTextboxesFootnotesEndnotesInStat()Specifies whether to include textboxes, footnotes and endnotes in word count statistics.
get_IsComposite() overrideReturns true as this node can have child nodes.
get_JustificationMode()Gets the character spacing adjustment of a document.
get_LastChild() constGets the last child of the node.
get_LastSection()Gets the last section in the document.
get_LayoutOptions() constGets a LayoutOptions object that represents options to control the layout process of this document.
get_Lists() constProvides access to the list formatting used in the document.
get_MailMerge()Returns a MailMerge object that represents the mail merge functionality for the document.
get_MailMergeSettings()Gets or sets the object that contains all of the mail merge information for a document.
get_NextNode() const
get_NextSibling()Gets the node immediately following this node.
get_NodeChangingCallback()Called when a node is inserted or removed in the document.
get_NodeType() const overrideReturns Document.
get_OriginalFileName() constGets the original file name of the document.
get_OriginalLoadFormat() constGets the format of the original document that was loaded into this object.
get_PackageCustomParts() constGets or sets the collection of custom parts (arbitrary content) that are linked to the OOXML package using “unknown relationships”.
get_PageColor()Gets or sets the page color of the document. This property is a simpler version of BackgroundShape.
get_PageCount()Gets the number of pages in the document as calculated by the most recent page layout operation.
get_ParentNode()Gets the immediate parent of this node.
get_PreviousSibling()Gets the node immediately preceding this node.
get_PrevNode() const
get_ProtectionType()Gets the currently active document protection type.
get_Range()Returns a Range object that represents the portion of a document that is contained in this node.
get_RemovePersonalInformation()Gets or sets a flag indicating that Microsoft Word will remove all user information from comments, revisions and document properties upon saving the document.
get_ResourceLoadingCallback() constAllows to control how external resources are loaded.
get_Revisions()Gets a collection of revisions (tracked changes) that exist in this document.
get_RevisionsView() constGets or sets a value indicating whether to work with the original or revised version of a document.
get_Sections()Returns a collection that represents all sections in the document.
get_ShadeFormData()Specifies whether to turn on the gray shading on form fields.
get_ShowGrammaticalErrors()Specifies whether to display grammar errors in this document.
get_ShowSpellingErrors()Specifies whether to display spelling errors in this document.
get_SpellingChecked()Returns true if the document has been checked for spelling.
get_Styles() constReturns a collection of styles defined in the document.
get_Theme()Gets the Theme object for this document.
get_TrackRevisions()True if changes are tracked when this document is edited in Microsoft Word.
get_Variables()Returns the collection of variables added to a document or template.
get_VbaProject() constGets or sets a VbaProject.
get_VersionsCount()Gets the number of document versions that was stored in the DOC document.
get_ViewOptions()Provides options to control how the document is displayed in Microsoft Word.
get_WarningCallback() constCalled during various document processing procedures when an issue is detected that might result in data or formatting fidelity loss.
get_Watermark()Provides access to the document watermark.
get_WebExtensionTaskPanes() constReturns a collection that represents a list of task pane add-ins.
get_WriteProtection()Provides access to the document write protection options.
GetAncestor(Aspose::Words::NodeType)Gets the first ancestor of the specified NodeType.
GetAncestorOf()
GetChild(Aspose::Words::NodeType, int32_t, bool)Returns an Nth child node that matches the specified type.
GetChildNodes(Aspose::Words::NodeType, bool)Returns a live collection of child nodes that match the specified type.
GetEnumerator() overrideProvides support for the for each style iteration over the child nodes of this node.
GetPageInfo(int32_t)Gets the page size, orientation and other information about a page that might be useful for printing or rendering.
GetText() overrideGets the text of this node and of all its children.
GetType() const override
ImportNode(const System::SharedPtr<Aspose::Words::Node>&, bool)Imports a node from another document to the current document.
ImportNode(const System::SharedPtr<Aspose::Words::Node>&, bool, Aspose::Words::ImportFormatMode)Imports a node from another document to the current document with an option to control formatting.
IndexOf(const System::SharedPtr<Aspose::Words::Node>&)Returns the index of the specified child node in the child node array.
InsertAfter(T, const System::SharedPtr<Aspose::Words::Node>&)
InsertBefore(T, const System::SharedPtr<Aspose::Words::Node>&)
Is(const System::TypeInfo&) const override
IsAncestorNode(const System::SharedPtr<Aspose::Words::Node>&)
JoinRunsWithSameFormatting()Joins runs with same formatting in all paragraphs of the document.
NextPreOrder(const System::SharedPtr<Aspose::Words::Node>&)Gets next node according to the pre-order tree traversal algorithm.
static NodeTypeToString(Aspose::Words::NodeType)A utility method that converts a node type enum value into a user friendly string.
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.
PrependChild(T)
PreviousPreOrder(const System::SharedPtr<Aspose::Words::Node>&)Gets the previous node according to the pre-order tree traversal algorithm.
Protect(Aspose::Words::ProtectionType)Protects the document from changes without changing the existing password or assigns a random password.
Protect(Aspose::Words::ProtectionType, const System::String&)Protects the document from changes and optionally sets a protection password.
RemoveAllChildren()Removes all the child nodes of the current node.
RemoveChild(T)
RemoveExternalSchemaReferences()Removes external XML schema references from this document.
RemoveMacros()Removes all macros (the VBA project) as well as toolbars and command customizations from the document.
RemoveSmartTags()Removes all SmartTag descendant nodes of the current node.
RenderToScale(int32_t, const System::SharedPtr<System::Drawing::Graphics>&, float, float, float)Renders a document page into a object to a specified scale.
RenderToSize(int32_t, const System::SharedPtr<System::Drawing::Graphics>&, float, float, float, float)Renders a document page into a object to a specified size.
Save(const System::String&)Saves the document to a file. Automatically determines the save format from the extension.
Save(const System::String&, Aspose::Words::SaveFormat)Saves the document to a file in the specified format.
Save(const System::String&, const System::SharedPtr<Aspose::Words::Saving::SaveOptions>&)Saves the document to a file using the specified save options.
Save(const System::SharedPtr<System::IO::Stream>&, Aspose::Words::SaveFormat)Saves the document to a stream using the specified format.
Save(const System::SharedPtr<System::IO::Stream>&, const System::SharedPtr<Aspose::Words::Saving::SaveOptions>&)Saves the document to a stream using the specified save options.
Save(std::basic_ostream<CharType, Traits>&, Aspose::Words::SaveFormat)
Save(std::basic_ostream<CharType, Traits>&, System::SharedPtr<Aspose::Words::Saving::SaveOptions>)
SelectNodes(const System::String&)Selects a list of nodes matching the XPath expression.
SelectSingleNode(const System::String&)Selects the first Node that matches the XPath expression.
set_AttachedTemplate(const System::String&)Setter for Aspose::Words::Document::get_AttachedTemplate.
set_AutomaticallyUpdateStyles(bool)Setter for Aspose::Words::Document::get_AutomaticallyUpdateStyles.
set_BackgroundShape(const System::SharedPtr<Aspose::Words::Drawing::Shape>&)Setter for Aspose::Words::DocumentBase::get_BackgroundShape.
set_CustomNodeId(int32_t)Setter for Aspose::Words::Node::get_CustomNodeId.
set_CustomXmlParts(const System::SharedPtr<Aspose::Words::Markup::CustomXmlPartCollection>&)Setter for Aspose::Words::Document::get_CustomXmlParts.
set_DefaultTabStop(double)Setter for Aspose::Words::Document::get_DefaultTabStop.
set_FontSettings(const System::SharedPtr<Aspose::Words::Fonts::FontSettings>&)Setter for Aspose::Words::Document::get_FontSettings.
set_GlossaryDocument(const System::SharedPtr<Aspose::Words::BuildingBlocks::GlossaryDocument>&)Setter for Aspose::Words::Document::get_GlossaryDocument.
set_GrammarChecked(bool)Setter for Aspose::Words::Document::get_GrammarChecked.
set_IncludeTextboxesFootnotesEndnotesInStat(bool)Specifies whether to include textboxes, footnotes and endnotes in word count statistics.
set_JustificationMode(Aspose::Words::Settings::JustificationMode)Sets the character spacing adjustment of a document.
set_MailMergeSettings(const System::SharedPtr<Aspose::Words::Settings::MailMergeSettings>&)Setter for Aspose::Words::Document::get_MailMergeSettings.
set_NextNode(const System::SharedPtr<Aspose::Words::Node>&)
set_NodeChangingCallback(const System::SharedPtr<Aspose::Words::INodeChangingCallback>&)Setter for Aspose::Words::DocumentBase::get_NodeChangingCallback.
set_PackageCustomParts(const System::SharedPtr<Aspose::Words::Markup::CustomPartCollection>&)Setter for Aspose::Words::Document::get_PackageCustomParts.
set_PageColor(System::Drawing::Color)Setter for Aspose::Words::DocumentBase::get_PageColor.
set_PrevNode(const System::SharedPtr<Aspose::Words::Node>&)
set_RemovePersonalInformation(bool)Setter for Aspose::Words::Document::get_RemovePersonalInformation.
set_ResourceLoadingCallback(const System::SharedPtr<Aspose::Words::Loading::IResourceLoadingCallback>&)Setter for Aspose::Words::DocumentBase::get_ResourceLoadingCallback.
set_RevisionsView(Aspose::Words::RevisionsView)Setter for Aspose::Words::Document::get_RevisionsView.
set_ShadeFormData(bool)Setter for Aspose::Words::Document::get_ShadeFormData.
set_ShowGrammaticalErrors(bool)Setter for Aspose::Words::Document::get_ShowGrammaticalErrors.
set_ShowSpellingErrors(bool)Setter for Aspose::Words::Document::get_ShowSpellingErrors.
set_SpellingChecked(bool)Setter for Aspose::Words::Document::get_SpellingChecked.
set_TrackRevisions(bool)Setter for Aspose::Words::Document::get_TrackRevisions.
set_VbaProject(const System::SharedPtr<Aspose::Words::Vba::VbaProject>&)Setter for Aspose::Words::Document::get_VbaProject.
set_WarningCallback(const System::SharedPtr<Aspose::Words::IWarningCallback>&)Setter for Aspose::Words::DocumentBase::get_WarningCallback.
SetParent(const System::SharedPtr<Aspose::Words::Node>&)
SetTemplateWeakPtr(uint32_t) override
StartTrackRevisions(const System::String&, System::DateTime)Starts automatically marking all further changes you make to the document programmatically as revision changes.
StartTrackRevisions(const System::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.
ToString(Aspose::Words::SaveFormat)Exports the content of the node into a string in the specified format.
ToString(const System::SharedPtr<Aspose::Words::Saving::SaveOptions>&)Exports the content of the node into a string using the specified save options.
static Type()
UnlinkFields()Unlinks fields in the whole document.
Unprotect()Removes protection from the document regardless of the password.
Unprotect(const System::String&)Removes protection from the document if a correct password is specified.
UpdateActualReferenceMarks()
UpdateFields()Updates the values of fields in the whole document.
UpdateListLabels()Updates list labels for all list items in the document.
UpdatePageLayout()Rebuilds the page layout of the document.
UpdateTableLayout()
UpdateThumbnail(const System::SharedPtr<Aspose::Words::Rendering::ThumbnailGeneratingOptions>&)Updates Thumbnail of the document according to the specified options.
UpdateThumbnail()Updates Thumbnail of the document using default options.
UpdateWordCount()Updates word count properties of the document.
UpdateWordCount(bool)Updates word count properties of the document, optionally updates Lines property.

Remarks

The Document is a central object in the Aspose.Words library.

To load an existing document in any of the LoadFormat formats, pass a file name or a stream into one of the Document constructors. To create a blank document, call the constructor without parameters.

Use one of the Save method overloads to save the document in any of the SaveFormat formats.

To draw document pages directly onto a Graphics object use RenderToScale() or RenderToSize() method.

To print the document, use one of the Print() methods.

MailMerge is the Aspose.Words’s reporting engine that allows to populate reports designed in Microsoft Word with data from various data sources quickly and easily. The data can be from a or an array of values. MailMerge will go through the records found in the data source and insert them into mail merge fields in the document growing it as necessary.

Document stores document-wide information such as Styles, BuiltInDocumentProperties, CustomDocumentProperties, lists and macros. Most of these objects are accessible via the corresponding properties of the Document.

The Document is a root node of a tree that contains all other nodes of the document. The tree is a Composite design pattern and in many ways similar to XmlDocument. The content of the document can be manipulated freely programmatically:

Consider using DocumentBuilder that simplifies the task of programmatically creating or populating the document tree.

The Document can contain only Section objects.

In Microsoft Word, a valid document needs to have at least one section.

See Also