Class Document

Class Document

Namespace: Aspose.Words
Assembly: Aspose.Words.dll (25.2.0)

Represents a Word document.

To learn more, visit the Working with Document documentation article.

public class Document : DocumentBase, IEnumerable<node>, IEnumerable, IXPathNavigable

Inheritance

objectNodeCompositeNodeDocumentBaseDocument

Implements

IEnumerable<node>, IEnumerable, IXPathNavigable

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Remarks

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

To load an existing document in any of the Aspose.Words.LoadFormat formats, pass a file name or a stream into one of the Aspose.Words.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 Aspose.Words.SaveFormat formats.

To draw document pages directly onto a Graphics object use Aspose.Words.Document.RenderToScale(System.Int32,System.Drawing.Graphics,System.Single,System.Single,System.Single) or Aspose.Words.Document.RenderToSize(System.Int32,System.Drawing.Graphics,System.Single,System.Single,System.Single,System.Single) method.

To print the document, use one of the Aspose.Words.Document.Print(System.String) methods.

Aspose.Words.Document.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 DataSet, DataTable, DataView, IDataReader 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.

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

The Aspose.Words.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:

  • The nodes of the document can be accessed via typed collections, for example Aspose.Words.Document.Sections, Aspose.Words.ParagraphCollection etc.
  • The nodes of the document can be selected by their node type using Aspose.Words.CompositeNode.GetChildNodes(Aspose.Words.NodeType,System.Boolean) or using an XPath query with Aspose.Words.CompositeNode.SelectNodes(System.String) or Aspose.Words.CompositeNode.SelectSingleNode(System.String).
  • Content nodes can be added or removed from anywhere in the document using Aspose.Words.CompositeNode.InsertBefore``1(``0,Aspose.Words.Node), Aspose.Words.CompositeNode.InsertAfter``1(``0,Aspose.Words.Node), Aspose.Words.CompositeNode.RemoveChild``1(``0) and other methods provided by the base class Aspose.Words.CompositeNode.
  • The formatting attributes of each node can be changed via the properties of that node.

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

The Aspose.Words.Document can contain only Aspose.Words.Section objects.

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

 English