Aspose::Words::Document class

Document class

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

class Document : public DocumentBase,
                 public ISectionAttrSource,
                 public 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>) overrideAccepts a visitor for visiting the end of the document.
AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>) overrideAccepts a visitor for visiting the start of the document.
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.
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::SharedPtr<Aspose::Words::Document> &)Copies styles from the specified template to a document.
CopyStylesFromTemplate(const System::String &)Copies styles from the specified template to a document.
Document()Creates a blank Word document.
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(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(std::istream &)Opens an existing document from a stream. Automatically detects the file format.
Document(std::istream &, const System::SharedPtr<Aspose::Words::Loading::LoadOptions> &)Opens an existing document from a stream. Allows to specify additional options such as an encryption password.
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.
ExtractPages(int32_t, int32_t, const System::SharedPtr<Aspose::Words::PageExtractOptions> &)Returns the Document object representing the specified range of pages and the given page extract options.
GetPageInfo(int32_t)Gets the page size, orientation and other information about a page that might be useful for printing or rendering.
JoinRunsWithSameFormatting()Joins runs with same formatting in all paragraphs of the 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.
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.
RemoveBlankPages()Removes blank pages from the document.
RemoveCustomizations()Removes toolbar and keyboard command customizations from the document.
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.
RenderToScale(int32_t, const System::SharedPtr<System::Drawing::Graphics> &, float, float, float)Renders a document page into a Graphics object to a specified scale.
RenderToSize(int32_t, const System::SharedPtr<System::Drawing::Graphics> &, float, float, float, float)Renders a document page into a Graphics object to a specified size.
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(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(std::basic_ostream<CharType, Traits> &, Aspose::Words::SaveFormat)Saves the document to a stream using the specified format.
Save(std::basic_ostream<CharType, Traits> &, const System::SharedPtr<Aspose::Words::Saving::SaveOptions> &)Saves the document to a stream using the specified save options.
StartTrackRevisions(const System::String &)Starts automatically marking all further changes you make to the document programmatically as revision changes.
StartTrackRevisions(const System::String &, System::DateTime)Starts automatically marking all further changes you make to the document programmatically as revision changes.
StopTrackRevisions()Stops automatic marking of document changes as revisions.
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()Updates the ActualReferenceMark property of all footnotes and endnotes in the document.
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()Implements an earlier approach to table column widths re-calculation that has known issues.
UpdateThumbnail()Updates Thumbnail of the document using default options.
UpdateThumbnail(const System::SharedPtr<Aspose::Words::Rendering::ThumbnailGeneratingOptions> &)Updates Thumbnail of the document according to the specified options.
UpdateWordCount()Updates word count properties of the document.
UpdateWordCount(bool)Updates word count properties of the document, optionally updates Lines property.
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_Bibliography()Gets the Bibliography object that represents the list of sources available in the document.
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_CustomDocumentProperties()Returns a collection that represents all the custom document properties of the document.
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_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_FirstSection()Gets the first section in the 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_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_JustificationMode()Gets or sets the character spacing adjustment of a document.
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_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_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_PageCount()Gets the number of pages in the document as calculated by the most recent page layout operation.
get_ProtectionType()Gets the currently active document protection type.
get_PunctuationKerning()Specifies whether kerning applies to both Latin text and punctuation.
get_ReadabilityStatistics()Provides readability score information for the document.
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_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_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_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.
set_AttachedTemplate(const System::String &)Sets the full path of the template attached to the document.
set_AutomaticallyUpdateStyles(bool)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.
set_CustomXmlParts(const System::SharedPtr<Aspose::Words::Markup::CustomXmlPartCollection> &)Sets the collection of Custom XML Data Storage Parts.
set_DefaultTabStop(double)Sets the interval (in points) between the default tab stops.
set_FontSettings(const System::SharedPtr<Aspose::Words::Fonts::FontSettings> &)Sets document font settings.
set_GlossaryDocument(const System::SharedPtr<Aspose::Words::BuildingBlocks::GlossaryDocument> &)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.
set_GrammarChecked(bool)Returns true if the document has been checked for grammar.
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> &)Sets the object that contains all of the mail merge information for a document.
set_PackageCustomParts(const System::SharedPtr<Aspose::Words::Markup::CustomPartCollection> &)Sets the collection of custom parts (arbitrary content) that are linked to the OOXML package using “unknown relationships”.
set_PunctuationKerning(bool)Specifies whether kerning applies to both Latin text and punctuation.
set_RemovePersonalInformation(bool)Sets a flag indicating that Microsoft Word will remove all user information from comments, revisions and document properties upon saving the document.
set_RevisionsView(Aspose::Words::RevisionsView)Sets a value indicating whether to work with the original or revised version of a document.
set_ShadeFormData(bool)Specifies whether to turn on the gray shading on form fields.
set_ShowGrammaticalErrors(bool)Specifies whether to display grammar errors in this document.
set_ShowSpellingErrors(bool)Specifies whether to display spelling errors in this document.
set_SpellingChecked(bool)Returns true if the document has been checked for spelling.
set_TrackRevisions(bool)True if changes are tracked when this document is edited in Microsoft Word.
set_VbaProject(const System::SharedPtr<Aspose::Words::Vba::VbaProject> &)Sets a VbaProject.
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.
ImportNode(const System::SharedPtr<Aspose::Words::Node> &, bool, Aspose::Words::ImportFormatMode, const System::SharedPtr<Aspose::Words::ImportFormatOptions> &)Imports a node from another document to the current document with an option to control formatting.
get_BackgroundShape() constGets or sets the background shape of the document. Can be null.
get_Document() const overrideGets this instance.
get_FontInfos() constProvides access to properties of fonts used in this document.
get_FootnoteSeparators() constProvides access to the footnote/endnote separators defined in the document.
get_Lists() constProvides access to the list formatting used in the document.
get_NodeChangingCallback()Called when a node is inserted or removed in the document.
get_PageColor()Gets or sets the page color of the document. This property is a simpler version of BackgroundShape.
get_ResourceLoadingCallback() constAllows to control how external resources are loaded.
get_Styles() constReturns a collection of styles defined in the document.
get_WarningCallback() constCalled during various document processing procedures when an issue is detected that might result in data or formatting fidelity loss.
set_BackgroundShape(const System::SharedPtr<Aspose::Words::Drawing::Shape> &)Sets the background shape of the document. Can be null.
set_NodeChangingCallback(const System::SharedPtr<Aspose::Words::INodeChangingCallback> &)Called when a node is inserted or removed in the document.
set_PageColor(System::Drawing::Color)Sets the page color of the document. This property is a simpler version of BackgroundShape.
set_ResourceLoadingCallback(const System::SharedPtr<Aspose::Words::Loading::IResourceLoadingCallback> &)Allows to control how external resources are loaded.
set_WarningCallback(const System::SharedPtr<Aspose::Words::IWarningCallback> &)Called during various document processing procedures when an issue is detected that might result in data or formatting fidelity loss.
virtual AcceptEnd(System::SharedPtr<Aspose::Words::DocumentVisitor>)When implemented in a derived class, calls the VisitXXXEnd method of the specified document visitor.
virtual AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>)When implemented in a derived class, calls the VisitXXXStart method of the specified document visitor.
AppendChild(T)Adds the specified node to the end of the list of child nodes for this node.
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.
GetText() overrideGets the text of this node and of all its children.
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> &)Inserts the specified node immediately after the specified reference node.
InsertBefore(T, const System::SharedPtr<Aspose::Words::Node> &)Inserts the specified node immediately before the specified reference node.
PrependChild(T)Adds the specified node to the beginning of the list of child nodes for this node.
RemoveAllChildren()Removes all the child nodes of the current node.
RemoveChild(T)Removes the specified child node.
RemoveSmartTags()Removes all SmartTag descendant nodes of the current node.
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.
get_Count()Gets the number of immediate children of this node.
get_FirstChild() constGets the first child of the node.
get_HasChildNodes()Returns true if this node has any child nodes.
get_IsComposite() overrideReturns true as this node can have child nodes.
get_LastChild() constGets the last child of the node.
virtual Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>)Accepts a visitor.
Clone(bool)Creates a duplicate of the node.
GetAncestor(Aspose::Words::NodeType)Gets the first ancestor of the specified NodeType.
virtual GetText()Gets the text of this node and of all its children.
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.
PreviousPreOrder(const System::SharedPtr<Aspose::Words::Node> &)Gets the previous node according to the pre-order tree traversal algorithm.
Remove()Removes itself from the parent.
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.
get_CustomNodeId() constSpecifies custom node identifier.
virtual get_Document() constGets the document to which this node belongs.
virtual get_IsComposite()Returns true if this node can contain other nodes.
get_NextSibling()Gets the node immediately following this node.
virtual get_NodeType() constGets the type of this node.
get_ParentNode()Gets the immediate parent of this node.
get_PreviousSibling()Gets the node immediately preceding this node.
get_Range()Returns a Range object that represents the portion of a document that is contained in this node.
set_CustomNodeId(int32_t)Specifies custom node identifier.

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