Aspose::Words Namespace Reference

Detailed Description

The Aspose.Words namespace provides classes for generating, converting, modifying, rendering and printing Microsoft Word documents without utilizing Microsoft Word.

Aspose.Words is written completely in C#, CLS compliant and contains only safe managed code. Microsoft Word is not required in order to use Aspose.Words.

The classes in the Aspose.Words namespace borrow best practices from two well-known frameworks: Microsoft Word Automation and System.Xml. A document in Aspose.Words is represented by a tree of nodes, much like in XML DOM. Where possible, class, method and property names match those found in Microsoft Word Automation.

The main classes in this namespace are:

  • Document is the main class of the object model that represents a Microsoft Word document.
  • DocumentBuilder provides an easy way to insert content and formatting into a document.
  • Node is the base class for all nodes in the document.
  • CompositeNode is the base class for all nodes of the document that can contain other nodes, for example Paragraph, Section and Table.

Namespaces

 BuildingBlocks
 The Aspose.Words.BuildingBlocks namespace provides classes that allow to access and use AutoText, AutoCorrect entries and Building Blocks in a document.
 
 Comparing
 The Aspose.Words.Comparing namespace provides classes and enumerations that allow to specify additional options when comparing documents.
 
 DigitalSignatures
 The Aspose.Words.DigitalSignatures namespace provides classes to sign documents and verify signatures.
 
 Drawing
 The Aspose.Words.Drawing namespace provides classes that allow to create and modify drawing objects.
 
 Fields
 The Aspose.Words.Fields namespace contains classes that represent Microsoft Word fields in a document.
 
 Fonts
 The Aspose.Words.Fonts namespace provides classes and enumerations to access information about fonts used in a document.
 
 Layout
 The Aspose.Words.Layout namespace provides classes that allow to access information such as on what page and where on a page particular document elements are positioned, when the document is formatted into pages.
 
 Lists
 The Aspose.Words.Lists namespace contains classes for working with bulleted and numbered lists defined in a document.
 
 Loading
 The Aspose.Words.Loading namespace provides classes and enumerations that allow to specify additional options when loading documents.
 
 MailMerging
 The Aspose.Words.MailMerging namespace contains classes of the "original" mail merge reporting engine.
 
 Markup
 The Aspose.Words.Markup namespace contains classes that represent customer defined semantics in a document: smart tags, custom XML and structured document tags (content controls).
 
 Math
 The Aspose.Words.Math namespace contains classes that represent Office Math elements.
 
 Notes
 The Aspose.Words.Notes namespace provides classes to work with Microsoft Word endnotes and footnotes.
 
 Properties
 The Aspose.Words.Properties namespace provides classes to work with custom and built-in document properties such as title, keywords, company etc.
 
 Rendering
 The Aspose.Words.Rendering namespace provides classes that allow to customize printing or rendering of documents.
 
 Replacing
 The Aspose.Words.Replacing namespace provides classes to manipulate with find/replace operations over the document tree.
 
 Reporting
 This namespace contains classes of the Aspose.Words' new reporting engine that supports report templates marked up with a language based on the LINQ Method Syntax.
 
 Saving
 The Aspose.Words.Saving namespace provides classes and enumerations that allow to specify additional options for saving or converting documents.
 
 Settings
 The Aspose.Words.Settings namespace contains classes and enums that are used when specifying various settings and options stored in a document. These are mail merge, write protection, compatibility and other settings.
 
 Shaping
 
 Tables
 The Aspose.Words.Tables namespace contains classes that represent tables, rows, cells and their formatting.
 
 Themes
 The Aspose.Words.Themes namespace provides classes that allow to access theme information in Microsoft Word documents.
 
 Vba
 The Aspose.Words.Vba namespace provides classes to work with VBA projects.
 
 WebExtensions
 The Aspose.Words.WebExtensions namespace provides classes that allow to customize elements and attributes that extend the XML vocabulary for representing Office Add-ins.
 

Classes

class  AbsolutePositionTab
 An absolute position tab is a character which is used to advance the position on the current line of text when displaying this WordprocessingML content. More...
 
class  Body
 Represents a container for the main text of a section. More...
 
class  Bookmark
 Represents a single bookmark. More...
 
class  BookmarkCollection
 A collection of Bookmark objects that represent the bookmarks in the specified range. More...
 
class  BookmarkEnd
 Represents an end of a bookmark in a Word document. More...
 
class  BookmarkStart
 Represents a start of a bookmark in a Word document. More...
 
class  Border
 Represents a border of an object. More...
 
class  BorderCollection
 A collection of Border objects. More...
 
class  BuildVersionInfo
 Provides information about the current product name and version. More...
 
class  CleanupOptions
 Allows to specify options for document cleaning. More...
 
class  Comment
 Represents a container for text of a comment. More...
 
class  CommentCollection
 Provides typed access to a collection of Comment nodes. More...
 
class  CommentRangeEnd
 Denotes the end of a region of text that has a comment associated with it. More...
 
class  CommentRangeStart
 Denotes the start of a region of text that has a comment associated with it. More...
 
class  CompositeNode
 Base class for nodes that can contain other nodes. More...
 
class  ConditionalStyle
 Represents special formatting applied to some area of a table with assigned table style. More...
 
class  ConditionalStyleCollection
 Represents a collection of ConditionalStyle objects. More...
 
class  ControlChar
 Control characters often encountered in documents. More...
 
class  ConvertUtil
 Provides helper functions to convert between various measurement units. More...
 
class  Details_DocumentReaderPluginLoadException
 Thrown during document load, when the plugin required for reading the document format cannot be loaded.
 
class  Details_FileCorruptedException
 Thrown during document load, when the document appears to be corrupted and impossible to load.
 
class  Details_IncorrectPasswordException
 Thrown if a document is encrypted with a password and the password specified when opening the document is incorrect or missing.
 
class  Details_UnsupportedFileFormatException
 Thrown during document load, when the document format is not recognized or not supported by Aspose.Words.
 
class  Document
 Represents a Word document. More...
 
class  DocumentBase
 Provides the abstract base class for a main document and a glossary document of a Word document. More...
 
class  DocumentBuilder
 Provides methods to insert text, images and other content, specify font, paragraph and section formatting. More...
 
class  DocumentVisitor
 Base class for custom document visitors. More...
 
class  EditableRange
 Represents a single editable range. More...
 
class  EditableRangeEnd
 Represents an end of an editable range in a Word document. More...
 
class  EditableRangeStart
 Represents a start of an editable range in a Word document. More...
 
class  FileFormatInfo
 Contains data returned by FileFormatUtil document format detection methods. More...
 
class  FileFormatUtil
 Provides utility methods for working with file formats, such as detecting file format or converting file extensions to/from file format enums. More...
 
class  Font
 Contains font attributes (font name, font size, color, and so on) for an object. More...
 
class  FrameFormat
 Represents frame related formatting for a paragraph. More...
 
class  HeaderFooter
 Represents a container for the header or footer text of a section. More...
 
class  HeaderFooterCollection
 Provides typed access to HeaderFooter nodes of a Section. More...
 
class  Hyphenation
 Provides methods for working with hyphenation dictionaries. These dictionaries prescribe where words of a specific language can be hyphenated. More...
 
interface  IDocumentReaderPlugin
 Defines an interface for external reader plugins that can read a file into a document. More...
 
interface  IHyphenationCallback
 Implemented by classes which can register hyphenation dictionaries. More...
 
class  ImageWatermarkOptions
 Contains options that can be specified when adding a watermark with image. More...
 
class  ImportFormatOptions
 Allows to specify various import options to format output. More...
 
class  Inline
 Base class for inline-level nodes that can have character formatting associated with them, but cannot have child nodes of their own. More...
 
class  InlineStory
 Base class for inline-level nodes that can contain paragraphs and tables. More...
 
interface  INodeChangingCallback
 Implement this interface if you want to receive notifications when nodes are inserted or removed in the document. More...
 
class  InternableComplexAttr
 Base class for internable complex attribute. Internable complex attribute should notify parent collection when going to be changed. More...
 
interface  IWarningCallback
 Implement this interface if you want to have your own custom method called to capture loss of fidelity warnings that can occur during document loading or saving. More...
 
class  License
 Provides methods to license the component. More...
 
class  Node
 Base class for all nodes of a Word document. More...
 
class  NodeChangingArgs
 Provides data for methods of the INodeChangingCallback interface. More...
 
class  NodeCollection
 Represents a collection of nodes of a specific type. More...
 
class  NodeImporter
 Allows to efficiently perform repeated import of nodes from one document to another. More...
 
class  NodeList
 Represents a collection of nodes matching an XPath query executed using the SelectNodes() method. More...
 
class  PageSetup
 Represents the page setup properties of a section. More...
 
class  Paragraph
 Represents a paragraph of text. More...
 
class  ParagraphCollection
 Provides typed access to a collection of Paragraph nodes. More...
 
class  ParagraphFormat
 Represents all the formatting for a paragraph. More...
 
class  PlainTextDocument
 Allows to extract plain-text representation of the document's content. More...
 
class  Range
 Represents a contiguous area in a document. More...
 
class  Revision
 Represents a revision (tracked change) in a document node or style. Use RevisionType to check the type of this revision. More...
 
class  RevisionCollection
 A collection of Revision objects that represent revisions in the document. More...
 
class  RevisionGroup
 Represents a group of sequential Revision objects. More...
 
class  RevisionGroupCollection
 A collection of RevisionGroup objects that represent revision groups in the document. More...
 
class  Run
 Represents a run of characters with the same font formatting. More...
 
class  RunCollection
 Provides typed access to a collection of Run nodes. More...
 
class  Section
 Represents a single section in a document. More...
 
class  SectionCollection
 A collection of Section objects in the document. More...
 
class  Shading
 Contains shading attributes for an object. More...
 
class  SignatureLineOptions
 Allows to specify options for signature line being inserted. Used in DocumentBuilder. More...
 
class  SpecialChar
 Base class for special characters in the document. More...
 
class  Story
 Base class for elements that contain block-level nodes Paragraph and Table. More...
 
class  Style
 Represents a single built-in or user-defined style. More...
 
class  StyleCollection
 A collection of Style objects that represent both the built-in and user-defined styles in a document. More...
 
class  SubDocument
 Represents a SubDocument - which is a reference to an externally stored document. More...
 
class  TableStyle
 Represents a table style. More...
 
class  TabStop
 Represents a single custom tab stop. The TabStop object is a member of the TabStopCollection collection. More...
 
class  TabStopCollection
 A collection of TabStop objects that represent custom tabs for a paragraph or a style. More...
 
class  TextColumn
 Represents a single text column. TextColumn is a member of the TextColumnCollection collection. The TextColumns collection includes all the columns in a section of a document. More...
 
class  TextColumnCollection
 A collection of TextColumn objects that represent all the columns of text in a section of a document. More...
 
class  TextWatermarkOptions
 Contains options that can be specified when adding a watermark with text. More...
 
class  VariableCollection
 A collection of document variables. More...
 
class  WarningInfo
 Contains information about a warning that Aspose.Words issued during document loading or saving. More...
 
class  WarningInfoCollection
 Represents a typed collection of WarningInfo objects. More...
 
class  Watermark
 Represents class to work with document watermark. More...
 

Typedefs

using DocumentReaderPluginLoadException = ExceptionWrapper< Details_DocumentReaderPluginLoadException >
 Thrown during document load, when the plugin required for reading the document format cannot be loaded. More...
 
using FileCorruptedException = ExceptionWrapper< Details_FileCorruptedException >
 Thrown during document load, when the document appears to be corrupted and impossible to load. More...
 
using IncorrectPasswordException = ExceptionWrapper< Details_IncorrectPasswordException >
 Thrown if a document is encrypted with a password and the password specified when opening the document is incorrect or missing. More...
 
using UnsupportedFileFormatException = ExceptionWrapper< Details_UnsupportedFileFormatException >
 Thrown during document load, when the document format is not recognized or not supported by Aspose.Words. More...
 

Enumerations

enum class  BorderType
 Specifies sides of a border. More...
 
enum class  BreakType
 Specifies type of a break inside a document. More...
 
enum class  CalendarType
 Specifies the type of a calendar. More...
 
enum class  ConditionalStyleType
 Represents possible table areas to which conditional formatting may be defined in a table style. More...
 
enum class  DocumentPositionMovement
 DocumentPositionMovement enumeration. More...
 
enum class  DropCapPosition
 Specifies the position for a drop cap text. More...
 
enum class  EditorType
 Specifies the set of possible aliases (or editing groups) which can be used as aliases to determine if the current user shall be allowed to edit a single range defined by an editable range within a document. More...
 
enum class  EmphasisMark
 Specifies possible types of emphasis mark. More...
 
enum class  HeaderFooterType
 Identifies the type of header or footer found in a Word file. More...
 
enum class  HeightRule
 Specifies the rule for determining the height of an object. More...
 
enum class  ImportFormatMode
 Specifies how formatting is merged when importing content from another document. More...
 
enum class  LicenseState
 LicenseState enumeration. More...
 
enum class  LineNumberRestartMode
 Determines when automatic line numbering restarts. More...
 
enum class  LineSpacingRule
 Specifies line spacing values for a paragraph. More...
 
enum class  LineStyle
 Specifies line style of a Border. More...
 
enum class  LoadFormat
 Indicates the format of the document that is to be loaded. More...
 
enum class  LoadFormatTest
 LoadFormatTest enumeration. More...
 
enum class  MeasurementUnits
 Specifies the unit of measurement. More...
 
enum class  NodeChangingAction
 Specifies the type of node change. More...
 
enum class  NodeType
 Specifies the type of a Word document node. More...
 
enum class  NumberStyle
 Specifies the number style for a list, footnotes and endnotes, page numbers. More...
 
enum class  Orientation
 Specifies page orientation. More...
 
enum class  OutlineLevel
 Specifies the outline level of a paragraph in the document. More...
 
enum class  PageBorderAppliesTo
 Specifies which pages the page border is printed on. More...
 
enum class  PageBorderDistanceFrom
 Specifies the positioning of the page border relative to the page margin. More...
 
enum class  PageVerticalAlignment
 Specifies vertical justification of text on each page. More...
 
enum class  PaperSize
 Specifies paper size. More...
 
enum class  ParagraphAlignment
 Specifies text alignment in a paragraph. More...
 
enum class  ProtectionType
 Protection type for a document. More...
 
enum class  RevisionsView
 Allows to specify whether to work with the original or revised version of a document. More...
 
enum class  RevisionType
 Specifies the type of change being tracked in Revision. More...
 
enum class  RunPrExpandFlags
 RunPrExpandFlags enumeration. More...
 
enum class  SaveFormat
 Indicates the format in which the document is saved. More...
 
enum class  SectionLayoutMode
 Specifies the layout mode for a section allowing to define the document grid behavior. More...
 
enum class  SectionStart
 The type of break at the beginning of the section. More...
 
enum class  StoryType
 Text of a Word document is stored in stories. StoryType identifies a story. More...
 
enum class  StyleIdentifier
 Locale independent style identifier. More...
 
enum class  StyleType
 Represents type of the style. More...
 
enum class  TabAlignment
 Specifies the alignment/type of a tab stop. More...
 
enum class  TabLeader
 Specifies the type of the leader line displayed under the tab character. More...
 
enum class  TextDmlEffect
 Dml text effect for text runs. More...
 
enum class  TextEffect
 Animation effect for text runs. More...
 
enum class  TextOrientation
 Specifies orientation of text on a page, in a table cell or a text frame. More...
 
enum class  TextureIndex
 Specifies shading texture. More...
 
enum class  Underline
 Indicates type of the underline applied to a font. More...
 
enum class  VisitorAction
 Allows the visitor to control the enumeration of nodes. More...
 
enum class  WarningSource
 Specifies the module that produces a warning during document loading or saving. More...
 
enum class  WarningType
 Specifies the type of a warning that is issued by Aspose.Words during document loading or saving. More...
 
enum class  WatermarkLayout
 Defines layout of the watermark relative to the watermark center. More...
 
enum class  WatermarkType
 Specifies the watermark type. More...
 

Typedef Documentation

◆ DocumentReaderPluginLoadException

using Aspose::Words::DocumentReaderPluginLoadException = typedef System::ExceptionWrapper<Details_DocumentReaderPluginLoadException>

Thrown during document load, when the plugin required for reading the document format cannot be loaded.

◆ FileCorruptedException

using Aspose::Words::FileCorruptedException = typedef System::ExceptionWrapper<Details_FileCorruptedException>

Thrown during document load, when the document appears to be corrupted and impossible to load.

Examples

Shows how to catch a FileCorruptedException.

try
{
// If we get an "Unreadable content" error message when trying to open a document using Microsoft Word,
// chances are that we will get an exception thrown when trying to load that document using Aspose.Words.
auto doc = MakeObject<Document>(MyDir + u"Corrupted document.docx");
}
{
std::cout << e->get_Message() << std::endl;
}

◆ IncorrectPasswordException

using Aspose::Words::IncorrectPasswordException = typedef System::ExceptionWrapper<Details_IncorrectPasswordException>

Thrown if a document is encrypted with a password and the password specified when opening the document is incorrect or missing.

◆ UnsupportedFileFormatException

using Aspose::Words::UnsupportedFileFormatException = typedef System::ExceptionWrapper<Details_UnsupportedFileFormatException>

Thrown during document load, when the document format is not recognized or not supported by Aspose.Words.

Enumeration Type Documentation

◆ BorderType

Specifies sides of a border.

Examples

Shows how to insert a paragraph with a top border.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Border> topBorder = builder->get_ParagraphFormat()->get_Borders()->idx_get(BorderType::Top);
topBorder->set_Color(System::Drawing::Color::get_Red());
topBorder->set_LineWidth(4.0);
topBorder->set_LineStyle(LineStyle::DashSmallGap);
builder->Writeln(u"Text with a red top border.");
doc->Save(ArtifactsDir + u"Border.ParagraphTopBorder.docx");
Enumerator
None 

Default value.

Bottom 

Specifies the bottom border of a paragraph or a table cell.

Left 

Specifies the left border of a paragraph or a table cell.

Right 

Specifies the right border of a paragraph or a table cell.

Top 

Specifies the top border of a paragraph or a table cell.

Horizontal 

Specifies the horizontal border between cells in a table or between conforming paragraphs.

Vertical 

Specifies the vertical border between cells in a table.

DiagonalDown 

Specifies the diagonal border in a table cell.

DiagonalUp 

Specifies the diagonal border in a table cell.

◆ BreakType

Specifies type of a break inside a document.

Examples

Shows how to create headers and footers in a document using DocumentBuilder.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Specify that we want different headers and footers for first, even and odd pages.
builder->get_PageSetup()->set_DifferentFirstPageHeaderFooter(true);
builder->get_PageSetup()->set_OddAndEvenPagesHeaderFooter(true);
// Create the headers, then add three pages to the document to display each header type.
builder->MoveToHeaderFooter(HeaderFooterType::HeaderFirst);
builder->Write(u"Header for the first page");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderEven);
builder->Write(u"Header for even pages");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
builder->Write(u"Header for all other pages");
builder->MoveToSection(0);
builder->Writeln(u"Page1");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page2");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page3");
doc->Save(ArtifactsDir + u"DocumentBuilder.HeadersAndFooters.docx");

Shows how to insert a Table of contents (TOC) into a document using heading styles as entries.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a table of contents for the first page of the document.
// Configure the table to pick up paragraphs with headings of levels 1 to 3.
// Also, set its entries to be hyperlinks that will take us
// to the location of the heading when left-clicked in Microsoft Word.
builder->InsertTableOfContents(u"\\o \"1-3\" \\h \\z \\u");
builder->InsertBreak(BreakType::PageBreak);
// Populate the table of contents by adding paragraphs with heading styles.
// Each such heading with a level between 1 and 3 will create an entry in the table.
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"Heading 1");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading2);
builder->Writeln(u"Heading 1.1");
builder->Writeln(u"Heading 1.2");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"Heading 2");
builder->Writeln(u"Heading 3");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading2);
builder->Writeln(u"Heading 3.1");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading3);
builder->Writeln(u"Heading 3.1.1");
builder->Writeln(u"Heading 3.1.2");
builder->Writeln(u"Heading 3.1.3");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading4);
builder->Writeln(u"Heading 3.1.3.1");
builder->Writeln(u"Heading 3.1.3.2");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading2);
builder->Writeln(u"Heading 3.2");
builder->Writeln(u"Heading 3.3");
// A table of contents is a field of a type that needs to be updated to show an up-to-date result.
doc->UpdateFields();
doc->Save(ArtifactsDir + u"DocumentBuilder.InsertToc.docx");

Shows how to apply and revert page setup settings to sections in a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Modify the page setup properties for the builder's current section and add text.
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_VerticalAlignment(PageVerticalAlignment::Center);
builder->Writeln(u"This is the first section, which landscape oriented with vertically centered text.");
// If we start a new section using a document builder,
// it will inherit the builder's current page setup properties.
builder->InsertBreak(BreakType::SectionBreakNewPage);
ASSERT_EQ(Orientation::Landscape, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Center, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
// We can revert its page setup properties to their default values using the "ClearFormatting" method.
builder->get_PageSetup()->ClearFormatting();
ASSERT_EQ(Orientation::Portrait, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Top, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
builder->Writeln(u"This is the second section, which is in default Letter paper size, portrait orientation and top alignment.");
doc->Save(ArtifactsDir + u"PageSetup.ClearFormatting.docx");
Enumerator
ParagraphBreak 

Break between paragraphs.

PageBreak 

Explicit page break.

ColumnBreak 

Explicit column break.

SectionBreakContinuous 

Specifies start of new section on the same page as the previous section.

SectionBreakNewColumn 

Specifies start of new section in the new column.

SectionBreakNewPage 

Specifies start of new section on a new page.

SectionBreakEvenPage 

Specifies start of new section on a new even page.

SectionBreakOddPage 

Specifies start of new section on a odd page.

LineBreak 

Explicit line break.

◆ CalendarType

Specifies the type of a calendar.

Examples

Shows how to automatically apply a custom format to field results as the fields are updated.

void FieldResultFormatting_()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto formatter = MakeObject<ExDocumentBuilder::FieldResultFormatter>(u"${0}", u"Date: {0}", u"Item # {0}:");
doc->get_FieldOptions()->set_ResultFormatter(formatter);
// Our field result formatter applies a custom format to newly created fields of three types of formats.
// Field result formatters apply new formatting to fields as they are updated,
// which happens as soon as we create them using this InsertField method overload.
// 1 - Numeric:
builder->InsertField(u" = 2 + 3 \\# $###");
ASSERT_EQ(u"$5", doc->get_Range()->get_Fields()->idx_get(0)->get_Result());
ASSERT_EQ(1, formatter->CountFormatInvocations(ApiExamples::ExDocumentBuilder::FieldResultFormatter::FormatInvocationType::Numeric));
// 2 - Date/time:
builder->InsertField(u"DATE \\@ \"d MMMM yyyy\"");
ASSERT_TRUE(doc->get_Range()->get_Fields()->idx_get(1)->get_Result().StartsWith(u"Date: "));
ASSERT_EQ(1, formatter->CountFormatInvocations(ApiExamples::ExDocumentBuilder::FieldResultFormatter::FormatInvocationType::DateTime));
// 3 - General:
builder->InsertField(u"QUOTE \"2\" \\* Ordinal");
ASSERT_EQ(u"Item # 2:", doc->get_Range()->get_Fields()->idx_get(2)->get_Result());
ASSERT_EQ(1, formatter->CountFormatInvocations(ApiExamples::ExDocumentBuilder::FieldResultFormatter::FormatInvocationType::General));
formatter->PrintFormatInvocations();
}
class FieldResultFormatter : public IFieldResultFormatter
{
public:
enum class FormatInvocationType
{
Numeric,
General,
};
private:
class FormatInvocation : public System::Object
{
public:
ApiExamples::ExDocumentBuilder::FieldResultFormatter::FormatInvocationType get_FormatInvocationType()
{
return pr_FormatInvocationType;
}
SharedPtr<System::Object> get_Value()
{
return pr_Value;
}
String get_OriginalFormat()
{
return pr_OriginalFormat;
}
String get_NewValue()
{
return pr_NewValue;
}
FormatInvocation(ApiExamples::ExDocumentBuilder::FieldResultFormatter::FormatInvocationType formatInvocationType, SharedPtr<System::Object> value,
String originalFormat, String newValue)
: pr_FormatInvocationType(((ApiExamples::ExDocumentBuilder::FieldResultFormatter::FormatInvocationType)0))
{
pr_Value = value;
pr_FormatInvocationType = formatInvocationType;
pr_OriginalFormat = originalFormat;
pr_NewValue = newValue;
}
private:
ApiExamples::ExDocumentBuilder::FieldResultFormatter::FormatInvocationType pr_FormatInvocationType;
SharedPtr<System::Object> pr_Value;
String pr_OriginalFormat;
String pr_NewValue;
};
public:
FieldResultFormatter(String numberFormat, String dateFormat, String generalFormat)
: mFormatInvocations(MakeObject<System::Collections::Generic::List<SharedPtr<ExDocumentBuilder::FieldResultFormatter::FormatInvocation>>>())
{
mNumberFormat = numberFormat;
mDateFormat = dateFormat;
mGeneralFormat = generalFormat;
}
String FormatNumeric(double value, String format) override
{
if (String::IsNullOrEmpty(mNumberFormat))
{
return nullptr;
}
String newValue = String::Format(mNumberFormat, value);
get_FormatInvocations()->Add(MakeObject<ExDocumentBuilder::FieldResultFormatter::FormatInvocation>(
ApiExamples::ExDocumentBuilder::FieldResultFormatter::FormatInvocationType::Numeric, System::ObjectExt::Box<double>(value), format, newValue));
return newValue;
}
String FormatDateTime(System::DateTime value, String format, CalendarType calendarType) override
{
if (String::IsNullOrEmpty(mDateFormat))
{
return nullptr;
}
String newValue = String::Format(mDateFormat, value);
get_FormatInvocations()->Add(MakeObject<ExDocumentBuilder::FieldResultFormatter::FormatInvocation>(
ApiExamples::ExDocumentBuilder::FieldResultFormatter::FormatInvocationType::DateTime,
System::ObjectExt::Box<String>(String::Format(u"{0} ({1})", value, calendarType)), format, newValue));
return newValue;
}
String Format(String value, GeneralFormat format) override
{
return Format(System::ObjectExt::Box<String>(value), format);
}
String Format(double value, GeneralFormat format) override
{
return Format(System::ObjectExt::Box<double>(value), format);
}
int CountFormatInvocations(ExDocumentBuilder::FieldResultFormatter::FormatInvocationType formatInvocationType)
{
if (formatInvocationType == ApiExamples::ExDocumentBuilder::FieldResultFormatter::FormatInvocationType::All)
{
return get_FormatInvocations()->get_Count();
}
std::function<bool(SharedPtr<FormatInvocation> f)> hasValidFormatInvocationType = [&formatInvocationType](SharedPtr<FormatInvocation> f)
{
return f->get_FormatInvocationType() == formatInvocationType;
};
return get_FormatInvocations()->LINQ_Count(hasValidFormatInvocationType);
}
void PrintFormatInvocations()
{
for (auto f : get_FormatInvocations())
{
std::cout << (String::Format(u"Invocation type:\t{0}\n", f->get_FormatInvocationType()) +
String::Format(u"\tOriginal value:\t\t{0}\n", f->get_Value()) +
String::Format(u"\tOriginal format:\t{0}\n", f->get_OriginalFormat()) +
String::Format(u"\tNew value:\t\t\t{0}\n", f->get_NewValue()))
<< std::endl;
}
}
private:
String mNumberFormat;
String mDateFormat;
String mGeneralFormat;
SharedPtr<System::Collections::Generic::List<SharedPtr<ExDocumentBuilder::FieldResultFormatter::FormatInvocation>>> mFormatInvocations;
SharedPtr<System::Collections::Generic::List<SharedPtr<ExDocumentBuilder::FieldResultFormatter::FormatInvocation>>> get_FormatInvocations()
{
return mFormatInvocations;
}
String Format(SharedPtr<System::Object> value, GeneralFormat format)
{
if (String::IsNullOrEmpty(mGeneralFormat))
{
return nullptr;
}
String newValue = String::Format(mGeneralFormat, value);
get_FormatInvocations()->Add(MakeObject<ExDocumentBuilder::FieldResultFormatter::FormatInvocation>(
ApiExamples::ExDocumentBuilder::FieldResultFormatter::FormatInvocationType::General, value, System::ObjectExt::ToString(format), newValue));
return newValue;
}
};
Enumerator
Gregorian 

The Gregorian calendar.

Hijri 

The Hijri Lunar calendar.

Hebrew 

The Hebrew Lunar calendar.

SakaEra 

The Saka Era calendar.

UmAlQura 

The Um-al-Qura calendar.

◆ ConditionalStyleType

Represents possible table areas to which conditional formatting may be defined in a table style.

Examples

Shows how to work with certain area styles of a table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Cell 1");
builder->InsertCell();
builder->Write(u"Cell 2");
builder->EndRow();
builder->InsertCell();
builder->Write(u"Cell 3");
builder->InsertCell();
builder->Write(u"Cell 4");
builder->EndTable();
// Create a custom table style.
auto tableStyle = System::DynamicCast<TableStyle>(doc->get_Styles()->Add(StyleType::Table, u"MyTableStyle1"));
// Conditional styles are formatting changes that affect only some of the table's cells
// based on a predicate, such as the cells being in the last row.
// Below are three ways of accessing a table style's conditional styles from the "ConditionalStyles" collection.
// 1 - By style type:
tableStyle->get_ConditionalStyles()
->get_Shading()
->set_BackgroundPatternColor(System::Drawing::Color::get_AliceBlue());
// 2 - By index:
tableStyle->get_ConditionalStyles()->idx_get(0)->get_Borders()->set_Color(System::Drawing::Color::get_Black());
tableStyle->get_ConditionalStyles()->idx_get(0)->get_Borders()->set_LineStyle(LineStyle::DotDash);
ASSERT_EQ(ConditionalStyleType::FirstRow, tableStyle->get_ConditionalStyles()->idx_get(0)->get_Type());
// 3 - As a property:
tableStyle->get_ConditionalStyles()->get_FirstRow()->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
// Apply padding and text formatting to conditional styles.
tableStyle->get_ConditionalStyles()->get_LastRow()->set_BottomPadding(10);
tableStyle->get_ConditionalStyles()->get_LastRow()->set_LeftPadding(10);
tableStyle->get_ConditionalStyles()->get_LastRow()->set_RightPadding(10);
tableStyle->get_ConditionalStyles()->get_LastRow()->set_TopPadding(10);
tableStyle->get_ConditionalStyles()->get_LastColumn()->get_Font()->set_Bold(true);
// List all possible style conditions.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<ConditionalStyle>>> enumerator = tableStyle->get_ConditionalStyles()->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<ConditionalStyle> currentStyle = enumerator->get_Current();
if (currentStyle != nullptr)
{
std::cout << System::EnumGetName(currentStyle->get_Type()) << std::endl;
}
}
}
// Apply the custom style, which contains all conditional styles, to the table.
table->set_Style(tableStyle);
// Our style applies some conditional styles by default.
ASSERT_EQ(TableStyleOptions::FirstRow | TableStyleOptions::FirstColumn | TableStyleOptions::RowBands, table->get_StyleOptions());
// We will need to enable all other styles ourselves via the "StyleOptions" property.
table->set_StyleOptions(table->get_StyleOptions() | TableStyleOptions::LastRow | TableStyleOptions::LastColumn);
doc->Save(ArtifactsDir + u"Table.ConditionalStyles.docx");
Enumerator
FirstRow 

Specifies formatting of the first row of a table.

FirstColumn 

Specifies formatting of the first column of a table.

LastRow 

Specifies formatting of the last row of a table.

LastColumn 

Specifies formatting of the last column of a table.

OddRowBanding 

Specifies formatting of odd-numbered row stripe.

OddColumnBanding 

Specifies formatting of odd-numbered column stripe.

EvenRowBanding 

Specifies formatting of even-numbered row stripe.

EvenColumnBanding 

Specifies formatting of even-numbered column stripe.

TopLeftCell 

Specifies formatting of the top left cell of a table.

TopRightCell 

Specifies formatting of the top right cell of a table.

BottomLeftCell 

Specifies formatting of the bottom left cell of a table.

BottomRightCell 

Specifies formatting of the bottom right cell of a table.

◆ DocumentPositionMovement

DocumentPositionMovement enumeration.

Enumerator
None 
Inside 
StartEnd 
Sibling 
Above 
Below 

◆ DropCapPosition

Specifies the position for a drop cap text.

Examples

Shows how to create a drop cap.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert one paragraph with a large letter that the text in the second and third paragraphs begins with.
builder->get_Font()->set_Size(54);
builder->Writeln(u"L");
builder->get_Font()->set_Size(18);
builder->Writeln(String(u"orem ipsum dolor sit amet, consectetur adipiscing elit, ") +
u"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ");
builder->Writeln(String(u"Ut enim ad minim veniam, quis nostrud exercitation ") + u"ullamco laboris nisi ut aliquip ex ea commodo consequat.");
// Currently, the second and third paragraphs will appear underneath the first.
// We can convert the first paragraph as a drop cap for the other paragraphs via its "ParagraphFormat" object.
// Set the "DropCapPosition" property to "DropCapPosition.Margin" to place the drop cap
// outside the left-hand side page margin if our text is left-to-right.
// Set the "DropCapPosition" property to "DropCapPosition.Normal" to place the drop cap within the page margins
// and to wrap the rest of the text around it.
// "DropCapPosition.None" is the default state for all paragraphs.
SharedPtr<ParagraphFormat> format = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat();
format->set_DropCapPosition(dropCapPosition);
doc->Save(ArtifactsDir + u"ParagraphFormat.DropCap.docx");
Enumerator
None 

The paragraph does not have a drop cap.

Normal 

The drop cap is positioned inside the text margin on the anchor paragraph.

Margin 

The drop cap is positioned outside the text margin on the anchor paragraph.

◆ EditorType

Specifies the set of possible aliases (or editing groups) which can be used as aliases to determine if the current user shall be allowed to edit a single range defined by an editable range within a document.

Examples

Shows how to limit the editing rights of editable ranges to a specific group/user.

void Visitor()
{
auto doc = MakeObject<Document>();
doc->Protect(ProtectionType::ReadOnly, u"MyPassword");
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(String(u"Hello world! Since we have set the document's protection level to read-only,") +
u" we cannot edit this paragraph without the password.");
// When we write-protect documents, editable ranges allow us to pick specific areas that users may edit.
// There are two mutually exclusive ways to narrow down the list of allowed editors.
// 1 - Specify a user:
SharedPtr<EditableRange> editableRange = builder->StartEditableRange()->get_EditableRange();
editableRange->set_SingleUser(u"john.doe@myoffice.com");
builder->Writeln(String::Format(u"This paragraph is inside the first editable range, can only be edited by {0}.", editableRange->get_SingleUser()));
builder->EndEditableRange();
ASSERT_EQ(EditorType::Unspecified, editableRange->get_EditorGroup());
// 2 - Specify a group that allowed users are associated with:
editableRange = builder->StartEditableRange()->get_EditableRange();
editableRange->set_EditorGroup(EditorType::Administrators);
builder->Writeln(String::Format(u"This paragraph is inside the first editable range, can only be edited by {0}.", editableRange->get_EditorGroup()));
builder->EndEditableRange();
ASSERT_EQ(String::Empty, editableRange->get_SingleUser());
builder->Writeln(u"This paragraph is outside the editable range, and cannot be edited by anybody.");
// Print details and contents of every editable range in the document.
auto editableRangePrinter = MakeObject<ExEditableRange::EditableRangePrinter>();
doc->Accept(editableRangePrinter);
std::cout << editableRangePrinter->ToText() << std::endl;
}
class EditableRangePrinter : public DocumentVisitor
{
public:
EditableRangePrinter() : mInsideEditableRange(false)
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
String ToText()
{
return mBuilder->ToString();
}
void Reset()
{
mBuilder->Clear();
mInsideEditableRange = false;
}
VisitorAction VisitEditableRangeStart(SharedPtr<EditableRangeStart> editableRangeStart) override
{
mBuilder->AppendLine(u" -- Editable range found! -- ");
mBuilder->AppendLine(String(u"\tID:\t\t") + editableRangeStart->get_Id());
if (editableRangeStart->get_EditableRange()->get_SingleUser() == String::Empty)
{
mBuilder->AppendLine(String(u"\tGroup:\t") + System::ObjectExt::ToString(editableRangeStart->get_EditableRange()->get_EditorGroup()));
}
else
{
mBuilder->AppendLine(String(u"\tUser:\t") + editableRangeStart->get_EditableRange()->get_SingleUser());
}
mBuilder->AppendLine(u"\tContents:");
mInsideEditableRange = true;
}
VisitorAction VisitEditableRangeEnd(SharedPtr<EditableRangeEnd> editableRangeEnd) override
{
mBuilder->AppendLine(u" -- End of editable range --\n");
mInsideEditableRange = false;
}
VisitorAction VisitRun(SharedPtr<Run> run) override
{
if (mInsideEditableRange)
{
mBuilder->AppendLine(String(u"\t\"") + run->get_Text() + u"\"");
}
}
private:
bool mInsideEditableRange;
SharedPtr<System::Text::StringBuilder> mBuilder;
};
Enumerator
Unspecified 

Means that editor type is not specified.

Administrators 

Specifies that users associated with the Administrators group shall be allowed to edit editable ranges using this editing type when document protection is enabled.

Contributors 

Specifies that users associated with the Contributors group shall be allowed to edit editable ranges using this editing type when document protection is enabled.

Current 

Specifies that users associated with the Current group shall be allowed to edit editable ranges using this editing type when document protection is enabled.

Editors 

Specifies that users associated with the Editors group shall be allowed to edit editable ranges using this editing type when document protection is enabled.

Everyone 

Specifies that all users that open the document shall be allowed to edit editable ranges using this editing type when document protection is enabled.

None 

Specifies that none of the users that open the document shall be allowed to edit editable ranges using this editing type when document protection is enabled.

Owners 

Specifies that users associated with the Owners group shall be allowed to edit editable ranges using this editing type when document protection is enabled.

Default 

Same as Unspecified.

◆ EmphasisMark

Specifies possible types of emphasis mark.

Examples

Shows how to add additional character rendered above/below the glyph-character.

auto builder = MakeObject<DocumentBuilder>();
// Possible types of emphasis mark:
// https://apireference.aspose.com/words/net/aspose.words/emphasismark
builder->get_Font()->set_EmphasisMark(emphasisMark);
builder->Write(u"Emphasis text");
builder->Writeln();
builder->get_Font()->ClearFormatting();
builder->Write(u"Simple text");
builder->get_Document()->Save(ArtifactsDir + u"Fonts.SetEmphasisMark.docx");
Enumerator
None 

No emphasis mark.

OverSolidCircle 

Emphasis mark is a solid black circle displayed above text.

OverComma 

Emphasis mark is a comma character displayed above text.

OverWhiteCircle 

Emphasis mark is an empty white circle displayed above text.

UnderSolidCircle 

Emphasis mark is a solid black circle displayed below text.

◆ HeaderFooterType

Identifies the type of header or footer found in a Word file.

Examples

Shows how to create headers and footers in a document using DocumentBuilder.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Specify that we want different headers and footers for first, even and odd pages.
builder->get_PageSetup()->set_DifferentFirstPageHeaderFooter(true);
builder->get_PageSetup()->set_OddAndEvenPagesHeaderFooter(true);
// Create the headers, then add three pages to the document to display each header type.
builder->MoveToHeaderFooter(HeaderFooterType::HeaderFirst);
builder->Write(u"Header for the first page");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderEven);
builder->Write(u"Header for even pages");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
builder->Write(u"Header for all other pages");
builder->MoveToSection(0);
builder->Writeln(u"Page1");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page2");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page3");
doc->Save(ArtifactsDir + u"DocumentBuilder.HeadersAndFooters.docx");
Enumerator
HeaderEven 

Header for even numbered pages.

HeaderPrimary 

Primary header, also used for odd numbered pages.

FooterEven 

Footer for even numbered pages.

FooterPrimary 

Primary footer, also used for odd numbered pages.

HeaderFirst 

Header for the first page of the section.

FooterFirst 

Footer for the first page of the section.

◆ HeightRule

Specifies the rule for determining the height of an object.

Examples

Shows how to format rows with a document builder.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Row 1, cell 1.");
// Start a second row, and then configure its height. The builder will apply these settings to
// its current row, as well as any new rows it creates afterwards.
builder->EndRow();
SharedPtr<RowFormat> rowFormat = builder->get_RowFormat();
rowFormat->set_Height(100);
rowFormat->set_HeightRule(HeightRule::Exactly);
builder->InsertCell();
builder->Write(u"Row 2, cell 1.");
builder->EndTable();
// The first row was unaffected by the padding reconfiguration and still holds the default values.
ASPOSE_ASSERT_EQ(0.0, table->get_Rows()->idx_get(0)->get_RowFormat()->get_Height());
ASSERT_EQ(HeightRule::Auto, table->get_Rows()->idx_get(0)->get_RowFormat()->get_HeightRule());
ASPOSE_ASSERT_EQ(100.0, table->get_Rows()->idx_get(1)->get_RowFormat()->get_Height());
ASSERT_EQ(HeightRule::Exactly, table->get_Rows()->idx_get(1)->get_RowFormat()->get_HeightRule());
doc->Save(ArtifactsDir + u"DocumentBuilder.SetRowFormatting.docx");
Enumerator
AtLeast 

The height will be at least the specified height in points. It will grow, if needed, to accommodate all text inside an object.

Exactly 

The height is specified exactly in points. Please note that if the text cannot fit inside the object of this height, it will appear truncated.

Auto 

The height will grow automatically to accommodate all text inside an object.

◆ ImportFormatMode

Specifies how formatting is merged when importing content from another document.

When you copy nodes from one document to another, this option specifies how formatting is resolved when both documents have a style with the same name, but different formatting.

The formatting is resolved as follows:

  1. Built-in styles are matched using their locale independent style identifier. User defined styles are matched using case-sensitive style name.
  2. If a matching style is not found in the destination document, the style (and all styles referenced by it) are copied into the destination document and the imported nodes are updated to reference the new style.
  3. If a matching style already exists in the destination document, what happens depends on the importFormatMode parameter passed to Document.ImportNode as described below.

When using the UseDestinationStyles option, if a matching style already exists in the destination document, the style is not copied and the imported nodes are updated to reference the existing style.

The drawback of using UseDestinationStyles is that the imported text might look different in the destination document comparing to the source document. For example, the "Heading 1" style in the source document uses Arial 16pt font and the "Heading 1" style in the destination document uses Times New Roman 14pt font. When importing text of "Heading 1" style with no other direct formatting, it will appear as Times New Roman 14pt font in the destination document.

KeepSourceFormatting option allows to make sure the imported content looks the same in the destination document like it looks in the source document. If a matching style already exists in the destination document, the source style formatting is expanded into direct Node attributes and the style is changed to Normal. If the style does not exist in the destination document, then the source style is imported into the destination document and applied to the imported node. Note, that it is not always possible to preserve the source style even if it does not exist in the destination document. In this case formating of such style will be expanded into direct Node attributes in favor of preserving original Node formatting.

The drawback of using KeepSourceFormatting is that if you perform several imports, you could end up with many styles in the destination document and that could make using consistent style formatting in Microsoft Word difficult for this document.

Using KeepDifferentStyles option allows to reuse destination styles if the formatting they provide is identical to the styles in the source document. If the style in destination document is different from the source then it is imported.

See also
Aspose::Words::DocumentBase::ImportNode(System::SharedPtr<Aspose::Words::Node>, bool, Aspose::Words::ImportFormatMode)
Examples

Shows how to insert a document into another document.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
auto builder = MakeObject<DocumentBuilder>(doc);
builder->MoveToDocumentEnd();
builder->InsertBreak(BreakType::PageBreak);
auto docToInsert = MakeObject<Document>(MyDir + u"Formatted elements.docx");
builder->InsertDocument(docToInsert, ImportFormatMode::KeepSourceFormatting);
builder->get_Document()->Save(ArtifactsDir + u"DocumentBuilder.InsertDocument.docx");
Enumerator
UseDestinationStyles 

Use the destination document styles and copy new styles. This is the default option.

KeepSourceFormatting 

Copy all required styles to the destination document, generate unique style names if needed.

KeepDifferentStyles 

Only copy styles that are different from those in the source document.

◆ LicenseState

LicenseState enumeration.

Enumerator
Evaluation 
Licensed 

◆ LineNumberRestartMode

Determines when automatic line numbering restarts.

See also
Aspose::Words::PageSetup
Aspose::Words::PageSetup::get_LineNumberRestartMode
Examples

Shows how to enable line numbering for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// We can use the section's PageSetup object to display numbers to the left of the section's text lines.
// This is the same behavior as a List object,
// but it covers the entire section and does not modify the text in any way.
// Our section will restart the numbering on each new page from 1 and display the number,
// if it is a multiple of 3, at 50pt to the left of the line.
SharedPtr<PageSetup> pageSetup = builder->get_PageSetup();
pageSetup->set_LineStartingNumber(1);
pageSetup->set_LineNumberCountBy(3);
pageSetup->set_LineNumberRestartMode(LineNumberRestartMode::RestartPage);
pageSetup->set_LineNumberDistanceFromText(50.0);
for (int i = 1; i <= 25; i++)
{
builder->Writeln(String::Format(u"Line {0}.", i));
}
// The line counter will skip any paragraph with the "SuppressLineNumbers" flag set to "true".
// This paragraph is on the 15th line, which is a multiple of 3, and thus would normally display a line number.
// The section's line counter will also ignore this line, treat the next line as the 15th,
// and continue the count from that point onward.
doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(14)->get_ParagraphFormat()->set_SuppressLineNumbers(true);
doc->Save(ArtifactsDir + u"PageSetup.LineNumbers.docx");
Enumerator
RestartPage 

Line numbering restarts at the start of every page.

RestartSection 

Line numbering restarts at the section start.

Continuous 

Line numbering continuous from the previous section.

◆ LineSpacingRule

Specifies line spacing values for a paragraph.

Enumerator
AtLeast 

The line spacing can be greater than or equal to, but never less than, the value specified in the LineSpacing property.

Exactly 

The line spacing never changes from the value specified in the LineSpacing property, even if a larger font is used within the paragraph.

Multiple 

The line spacing is specified in the LineSpacing property as the number of lines. One line equals 12 points.

◆ LineStyle

Specifies line style of a Border.

Examples

Shows how to insert a string surrounded by a border into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_Font()->get_Border()->set_Color(System::Drawing::Color::get_Green());
builder->get_Font()->get_Border()->set_LineWidth(2.5);
builder->get_Font()->get_Border()->set_LineStyle(LineStyle::DashDotStroker);
builder->Write(u"Text surrounded by green border.");
doc->Save(ArtifactsDir + u"Border.FontBorder.docx");
Enumerator
None 
Single 
Thick 
Double 
Hairline 
Dot 
DashLargeGap 
DotDash 
DotDotDash 
Triple 
ThinThickSmallGap 
ThickThinSmallGap 
ThinThickThinSmallGap 
ThinThickMediumGap 
ThickThinMediumGap 
ThinThickThinMediumGap 
ThinThickLargeGap 
ThickThinLargeGap 
ThinThickThinLargeGap 
Wave 
DoubleWave 
DashSmallGap 
DashDotStroker 
Emboss3D 
Engrave3D 
Outset 
Inset 

◆ LoadFormat

Indicates the format of the document that is to be loaded.

Examples

Shows how save a web page as a .docx file.

const String url = u"https://www.aspose.com/";
{
auto client = MakeObject<System::Net::WebClient>();
{
auto stream = MakeObject<System::IO::MemoryStream>(client->DownloadData(url));
// The URL is used again as a baseUri to ensure that any relative image paths are retrieved correctly.
auto options = MakeObject<LoadOptions>(LoadFormat::Html, u"", url);
// Load the HTML document from stream and pass the LoadOptions object.
auto doc = MakeObject<Document>(stream, options);
// At this stage, we can read and edit the document's contents and then save it to the local file system.
doc->Save(ArtifactsDir + u"Document.InsertHtmlFromWebPage.docx");
}
}

Shows how to use the FileFormatUtil methods to detect the format of a document.

// Load a document from a file that is missing a file extension, and then detect its file format.
{
SharedPtr<System::IO::FileStream> docStream = System::IO::File::OpenRead(MyDir + u"Word document with missing file extension");
SharedPtr<FileFormatInfo> info = FileFormatUtil::DetectFileFormat(docStream);
LoadFormat loadFormat = info->get_LoadFormat();
ASSERT_EQ(LoadFormat::Doc, loadFormat);
// Below are two methods of converting a LoadFormat to its corresponding SaveFormat.
// 1 - Get the file extension string for the LoadFormat, then get the corresponding SaveFormat from that string:
String fileExtension = FileFormatUtil::LoadFormatToExtension(loadFormat);
// 2 - Convert the LoadFormat directly to its SaveFormat:
saveFormat = FileFormatUtil::LoadFormatToSaveFormat(loadFormat);
// Load a document from the stream, and then save it to the automatically detected file extension.
auto doc = MakeObject<Document>(docStream);
ASSERT_EQ(u".doc", FileFormatUtil::SaveFormatToExtension(saveFormat));
doc->Save(ArtifactsDir + u"File.SaveToDetectedFileFormat" + FileFormatUtil::SaveFormatToExtension(saveFormat));
}

Shows how to specify a base URI when opening an html document.

// Suppose we want to load an .html document that contains an image linked by a relative URI
// while the image is in a different location. In that case, we will need to resolve the relative URI into an absolute one.
// We can provide a base URI using an HtmlLoadOptions object.
auto loadOptions = MakeObject<HtmlLoadOptions>(LoadFormat::Html, u"", ImageDir);
ASSERT_EQ(LoadFormat::Html, loadOptions->get_LoadFormat());
auto doc = MakeObject<Document>(MyDir + u"Missing image.html", loadOptions);
// While the image was broken in the input .html, our custom base URI helped us repair the link.
auto imageShape = System::DynamicCast<Shape>(doc->GetChildNodes(NodeType::Shape, true)->idx_get(0));
ASSERT_TRUE(imageShape->get_IsImage());
// This output document will display the image that was missing.
doc->Save(ArtifactsDir + u"HtmlLoadOptions.BaseUri.docx");
Enumerator
Auto 

Instructs Aspose.Words to recognize the format automatically.

Doc 

Microsoft Word 95 or Word 97 - 2003 Document.

Dot 

Microsoft Word 95 or Word 97 - 2003 Template.

DocPreWord60 

The document is in pre-Word 95 format. Aspose.Words does not currently support loading such documents.

Docx 

Office Open XML WordprocessingML Document (macro-free).

Docm 

Office Open XML WordprocessingML Macro-Enabled Document.

Dotx 

Office Open XML WordprocessingML Template (macro-free).

Dotm 

Office Open XML WordprocessingML Macro-Enabled Template.

FlatOpc 

Office Open XML WordprocessingML stored in a flat XML file instead of a ZIP package.

FlatOpcMacroEnabled 

Office Open XML WordprocessingML Macro-Enabled Document stored in a flat XML file instead of a ZIP package.

FlatOpcTemplate 

Office Open XML WordprocessingML Template (macro-free) stored in a flat XML file instead of a ZIP package.

FlatOpcTemplateMacroEnabled 

Office Open XML WordprocessingML Macro-Enabled Template stored in a flat XML file instead of a ZIP package.

Rtf 

RTF format.

WordML 

Microsoft Word 2003 WordprocessingML format.

Html 

HTML format.

Mhtml 

MHTML (Web archive) format.

Mobi 

MOBI is an eBook format used by the MobiPocket Reader and Amazon Kindle Readers.

Chm 

CHM (Compiled HTML Help) format.

Odt 

ODF Text Document.

Ott 

ODF Text Document Template.

Text 

Plain Text.

Markdown 

Markdown text document.

Pdf 

Pdf document.

Unknown 

Unrecognized format, cannot be loaded by Aspose.Words.

◆ LoadFormatTest

LoadFormatTest enumeration.

Enumerator
TestDocxDml 

◆ MeasurementUnits

Specifies the unit of measurement.

Enumerator
Inches 

Inches.

Centimeters 

Centimeters.

Millimeters 

Millimeters.

Points 

Points.

Picas 

Picas (commonly used in traditional typewriter font spacing).

◆ NodeChangingAction

Specifies the type of node change.

See also
Aspose::Words::NodeChangingArgs
Aspose::Words::NodeChangingArgs::get_Action
Examples

Shows how to use a NodeChangingCallback to monitor changes to the document tree in real-time as we edit it.

void NodeChangingCallback()
{
auto doc = MakeObject<Document>();
doc->set_NodeChangingCallback(MakeObject<ExNode::NodeChangingPrinter>());
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
builder->StartTable();
builder->InsertCell();
builder->Write(u"Cell 1");
builder->InsertCell();
builder->Write(u"Cell 2");
builder->EndTable();
builder->InsertImage(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"));
builder->get_CurrentParagraph()->get_ParentNode()->RemoveAllChildren();
}
class NodeChangingPrinter : public INodeChangingCallback
{
public:
void NodeInserting(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Insert, args->get_Action());
ASPOSE_ASSERT_EQ(nullptr, args->get_OldParent());
}
void NodeInserted(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Insert, args->get_Action());
ASSERT_FALSE(args->get_NewParent() == nullptr);
std::cout << "Inserted node:" << std::endl;
std::cout << String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()) << std::endl;
if (args->get_Node()->GetText().Trim() != u"")
{
std::cout << "\tText:\t\"" << args->get_Node()->GetText().Trim() << "\"" << std::endl;
}
std::cout << "\tHash:\t" << System::ObjectExt::GetHashCode(args->get_Node()) << std::endl;
std::cout << String::Format(u"\tParent:\t{0} ({1})", args->get_NewParent()->get_NodeType(), System::ObjectExt::GetHashCode(args->get_NewParent()))
<< std::endl;
}
void NodeRemoving(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Remove, args->get_Action());
}
void NodeRemoved(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Remove, args->get_Action());
ASSERT_TRUE(args->get_NewParent() == nullptr);
std::cout << String::Format(u"Removed node: {0} ({1})", args->get_Node()->get_NodeType(), System::ObjectExt::GetHashCode(args->get_Node()))
<< std::endl;
}
};
Enumerator
Insert 

A node is being inserted in the tree.

Remove 

A node is being removed from the tree.

◆ NodeType

Specifies the type of a Word document node.

Examples

Shows how to traverse through a composite node's collection of child nodes.

auto doc = MakeObject<Document>();
// Add two runs and one shape as child nodes to the first paragraph of this document.
auto paragraph = System::DynamicCast<Paragraph>(doc->GetChild(NodeType::Paragraph, 0, true));
paragraph->AppendChild(MakeObject<Run>(doc, u"Hello world! "));
auto shape = MakeObject<Shape>(doc, ShapeType::Rectangle);
shape->set_Width(200);
shape->set_Height(200);
// Note that the 'CustomNodeId' is not saved to an output file and exists only during the node lifetime.
shape->set_CustomNodeId(100);
shape->set_WrapType(WrapType::Inline);
paragraph->AppendChild(shape);
paragraph->AppendChild(MakeObject<Run>(doc, u"Hello again!"));
// Iterate through the paragraph's collection of immediate children,
// and print any runs or shapes that we find within.
SharedPtr<NodeCollection> children = paragraph->get_ChildNodes();
ASSERT_EQ(3, paragraph->get_ChildNodes()->get_Count());
for (auto child : System::IterateOver(children))
{
switch (child->get_NodeType())
{
std::cout << "Run contents:" << std::endl;
std::cout << "\t\"" << child->GetText().Trim() << "\"" << std::endl;
break;
auto childShape = System::DynamicCast<Shape>(child);
std::cout << "Shape:" << std::endl;
std::cout << String::Format(u"\t{0}, {1}x{2}", childShape->get_ShapeType(), childShape->get_Width(), childShape->get_Height()) << std::endl;
ASSERT_EQ(100, shape->get_CustomNodeId());
break;
}
default:
break;
}
}
Enumerator
Any 

Indicates all node types. Allows to select all children.

Document 

A Document object that, as the root of the document tree, provides access to the entire Word document. A Document node can have Section nodes.

Section 

A Section object that corresponds to one section in a Word document. A Section node can have Body and HeaderFooter nodes.

Body 

A Body object that contains the main text of a section (main text story). A Body node can have Paragraph and Table nodes.

HeaderFooter 

A HeaderFooter object that contains text of a particular header or footer inside a section. A HeaderFooter node can have Paragraph and Table nodes.

Table 

A Table object that represents a table in a Word document. A Table node can have Row nodes.

Row 

A row of a table. A Row node can have Cell nodes.

Cell 

A cell of a table row. A Cell node can have Paragraph and Table nodes.

Paragraph 

A paragraph of text. A Paragraph node is a container for inline level elements Run, FieldStart, FieldSeparator, FieldEnd, FormField, Shape, GroupShape, Footnote, Comment, SpecialChar, as well as BookmarkStart and BookmarkEnd.

BookmarkStart 

A beginning of a bookmark marker.

BookmarkEnd 

An end of a bookmark marker.

EditableRangeStart 

A beginning of an editable range.

EditableRangeEnd 

An end of an editable range.

MoveFromRangeStart 

A beginning of an MoveFrom range.

MoveFromRangeEnd 

An end of an MoveFrom range.

MoveToRangeStart 

A beginning of an MoveTo range.

MoveToRangeEnd 

An end of an MoveTo range.

GroupShape 

A group of shapes, images, OLE objects or other group shapes. A GroupShape node can contain other Shape and GroupShape nodes.

Shape 

A drawing object, such as an OfficeArt shape, image or an OLE object. A Shape node can contain Paragraph and Table nodes.

Comment 

A comment in a Word document. A Comment node can have Paragraph and Table nodes.

Footnote 

A footnote or endnote in a Word document. A Footnote node can have Paragraph and Table nodes.

Run 

A run of text.

FieldStart 

A special character that designates the start of a Word field.

FieldSeparator 

A special character that separates the field code from the field result.

FieldEnd 

A special character that designates the end of a Word field.

FormField 

A form field.

SpecialChar 

A special character that is not one of the more specific special character types.

SmartTag 

A smart tag around one or more inline structures (runs, images, fields,etc.) within a paragraph.

StructuredDocumentTag 

Allows to define customer-specific information and its means of presentation.

StructuredDocumentTagRangeStart 

A start of ranged structured document tag which accepts multi-sections content.

StructuredDocumentTagRangeEnd 

A end of ranged structured document tag which accepts multi-sections content.

GlossaryDocument 

A glossary document within the main document.

BuildingBlock 

A building block within a glossary document (e.g. glossary document entry).

CommentRangeStart 

A marker node that represents the start of a commented range.

CommentRangeEnd 

A marker node that represents the end of a commented range.

OfficeMath 

An Office Math object. Can be equation, function, matrix or one of other mathematical objects. Can be a collection of mathematical object and also can contain some non-mathematical objects such as runs of text.

SubDocument 

A subdocument node which is a link to another document.

Null 

Reserved for internal use by Aspose.Words.

◆ NumberStyle

Specifies the number style for a list, footnotes and endnotes, page numbers.

Examples

Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.

auto doc = MakeObject<Document>();
// A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
// We can create nested lists by increasing the indent level.
// We can begin and end a list by using a document builder's "ListFormat" property.
// Each paragraph that we add between a list's start and the end will become an item in the list.
// Create a list from a Microsoft Word template, and customize the first two of its list levels.
SharedPtr<List> list = doc->get_Lists()->Add(ListTemplate::NumberDefault);
SharedPtr<ListLevel> listLevel = list->get_ListLevels()->idx_get(0);
listLevel->get_Font()->set_Color(System::Drawing::Color::get_Red());
listLevel->get_Font()->set_Size(24);
listLevel->set_NumberStyle(NumberStyle::OrdinalText);
listLevel->set_StartAt(21);
listLevel->set_NumberFormat(u"\x0000");
listLevel->set_NumberPosition(-36);
listLevel->set_TextPosition(144);
listLevel->set_TabPosition(144);
listLevel = list->get_ListLevels()->idx_get(1);
listLevel->set_Alignment(ListLevelAlignment::Right);
listLevel->set_NumberStyle(NumberStyle::Bullet);
listLevel->get_Font()->set_Name(u"Wingdings");
listLevel->get_Font()->set_Color(System::Drawing::Color::get_Blue());
listLevel->get_Font()->set_Size(24);
// This NumberFormat value will create star-shaped bullet list symbols.
listLevel->set_NumberFormat(u"\xf0af");
listLevel->set_TrailingCharacter(ListTrailingCharacter::Space);
listLevel->set_NumberPosition(144);
// Create paragraphs and apply both list levels of our custom list formatting to them.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_ListFormat()->set_List(list);
builder->Writeln(u"The quick brown fox...");
builder->Writeln(u"The quick brown fox...");
builder->get_ListFormat()->ListIndent();
builder->Writeln(u"jumped over the lazy dog.");
builder->Writeln(u"jumped over the lazy dog.");
builder->get_ListFormat()->ListOutdent();
builder->Writeln(u"The quick brown fox...");
builder->get_ListFormat()->RemoveNumbers();
builder->get_Document()->Save(ArtifactsDir + u"Lists.CreateCustomList.docx");
Enumerator
Arabic 

Arabic numbering (1, 2, 3, ...)

UppercaseRoman 

Upper case Roman (I, II, III, ...)

LowercaseRoman 

Lower case Roman (i, ii, iii, ...)

UppercaseLetter 

Upper case Letter (A, B, C, ...)

LowercaseLetter 

Lower case letter (a, b, c, ...)

Ordinal 

Ordinal (1st, 2nd, 3rd, ...)

Number 

Numbered (One, Two, Three, ...)

OrdinalText 

Ordinal (text) (First, Second, Third, ...)

Hex 

Hexadecimal: 8, 9, A, B, C, D, E, F, 10, 11, 12.

ChicagoManual 

Chicago Manual of Style: *, †, †

Kanji 

Ideograph-digital.

KanjiDigit 

Japanese counting.

AiueoHalfWidth 

Aiueo.

IrohaHalfWidth 

Iroha.

ArabicFullWidth 

Full-width Arabic: 1, 2, 3, 4.

ArabicHalfWidth 

Half-width Arabic: 1, 2, 3, 4.

KanjiTraditional 

Japanese legal.

KanjiTraditional2 

Japanese digital ten thousand.

NumberInCircle 

Enclosed circles.

DecimalFullWidth 

Decimal full width: 1, 2, 3, 4.

Aiueo 

Aiueo full width.

Iroha 

Iroha full width.

LeadingZero 

Leading Zero (01, 02,..., 09, 10, 11,..., 99, 100, 101,...)

Bullet 

Bullet (check the character code in the text)

Ganada 

Korean Ganada.

Chosung 

Korea Chosung.

GB1 

Enclosed full stop.

GB2 

Enclosed parenthesis.

GB3 

Enclosed circle Chinese.

GB4 

Ideograph enclosed circle.

Zodiac1 

Ideograph traditional.

Zodiac2 

Ideograph Zodiac.

Zodiac3 

Ideograph Zodiac traditional.

TradChinNum1 

Taiwanese counting.

TradChinNum2 

Ideograph legal traditional.

TradChinNum3 

Taiwanese counting thousand.

TradChinNum4 

Taiwanese digital.

SimpChinNum1 

Chinese counting.

SimpChinNum2 

Chinese legal simplified.

SimpChinNum3 

Chinese counting thousand.

SimpChinNum4 

Chinese (not implemented)

HanjaRead 

Korean digital.

HanjaReadDigit 

Korean counting.

Hangul 

Korea legal.

Hanja 

Korea digital2.

Hebrew1 

Hebrew-1.

Arabic1 

Arabic alpha.

Hebrew2 

Hebrew-2.

Arabic2 

Arabic abjad.

HindiLetter1 

Hindi vowels.

HindiLetter2 

Hindi consonants.

HindiArabic 

Hindi numbers.

HindiCardinalText 

Hindi descriptive (cardinals)

ThaiLetter 

Thai letters.

ThaiArabic 

Thai numbers.

ThaiCardinalText 

Thai descriptive (cardinals)

VietCardinalText 

Vietnamese descriptive (cardinals)

NumberInDash 

Page number format: - 1 -, - 2 -, - 3 -, - 4 -.

LowercaseRussian 

Lowercase Russian alphabet.

UppercaseRussian 

Uppercase Russian alphabet.

None 

No bullet or number.

Custom 

Custom number format. It is supported by DOCX format only.

◆ Orientation

Specifies page orientation.

Examples

Shows how to apply and revert page setup settings to sections in a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Modify the page setup properties for the builder's current section and add text.
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_VerticalAlignment(PageVerticalAlignment::Center);
builder->Writeln(u"This is the first section, which landscape oriented with vertically centered text.");
// If we start a new section using a document builder,
// it will inherit the builder's current page setup properties.
builder->InsertBreak(BreakType::SectionBreakNewPage);
ASSERT_EQ(Orientation::Landscape, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Center, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
// We can revert its page setup properties to their default values using the "ClearFormatting" method.
builder->get_PageSetup()->ClearFormatting();
ASSERT_EQ(Orientation::Portrait, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Top, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
builder->Writeln(u"This is the second section, which is in default Letter paper size, portrait orientation and top alignment.");
doc->Save(ArtifactsDir + u"PageSetup.ClearFormatting.docx");
Enumerator
Portrait 

Portrait page orientation (narrow and tall).

Landscape 

Landscape page orientation (wide and short).

◆ OutlineLevel

Specifies the outline level of a paragraph in the document.

Enumerator
Level1 

The paragraph is at the outline level 1 (topmost level).

Level2 

The paragraph is at the outline level 2.

Level3 

The paragraph is at the outline level 3.

Level4 

The paragraph is at the outline level 4.

Level5 

The paragraph is at the outline level 5.

Level6 

The paragraph is at the outline level 6.

Level7 

The paragraph is at the outline level 7.

Level8 

The paragraph is at the outline level 8.

Level9 

The paragraph is at the outline level 9.

BodyText 

The paragraph is at the level of the main text.

◆ PageBorderAppliesTo

Specifies which pages the page border is printed on.

See also
Aspose::Words::PageSetup
Aspose::Words::PageSetup::get_BorderAppliesTo
Examples

Shows how to create a wide blue band border at the top of the first page.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_BorderAlwaysInFront(false);
pageSetup->set_BorderDistanceFrom(PageBorderDistanceFrom::PageEdge);
pageSetup->set_BorderAppliesTo(PageBorderAppliesTo::FirstPage);
SharedPtr<Border> border = pageSetup->get_Borders()->idx_get(BorderType::Top);
border->set_LineStyle(LineStyle::Single);
border->set_LineWidth(30);
border->set_Color(System::Drawing::Color::get_Blue());
border->set_DistanceFromText(0);
doc->Save(ArtifactsDir + u"PageSetup.PageBorderProperties.docx");
Enumerator
AllPages 

Page border is shown on all pages of the section.

FirstPage 

Page border is shown on the first page of the section only.

OtherPages 

Page border is shown on all pages except the first page of the section.

◆ PageBorderDistanceFrom

Specifies the positioning of the page border relative to the page margin.

See also
Aspose::Words::PageSetup
Aspose::Words::PageSetup::get_BorderDistanceFrom
Examples

Shows how to create a wide blue band border at the top of the first page.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_BorderAlwaysInFront(false);
pageSetup->set_BorderDistanceFrom(PageBorderDistanceFrom::PageEdge);
pageSetup->set_BorderAppliesTo(PageBorderAppliesTo::FirstPage);
SharedPtr<Border> border = pageSetup->get_Borders()->idx_get(BorderType::Top);
border->set_LineStyle(LineStyle::Single);
border->set_LineWidth(30);
border->set_Color(System::Drawing::Color::get_Blue());
border->set_DistanceFromText(0);
doc->Save(ArtifactsDir + u"PageSetup.PageBorderProperties.docx");
Enumerator
Text 

Border position is measured from the page margin.

PageEdge 

Border position is measured from the page edge.

◆ PageVerticalAlignment

Specifies vertical justification of text on each page.

See also
Aspose::Words::PageSetup
Aspose::Words::PageSetup::get_VerticalAlignment
Examples

Shows how to apply and revert page setup settings to sections in a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Modify the page setup properties for the builder's current section and add text.
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_VerticalAlignment(PageVerticalAlignment::Center);
builder->Writeln(u"This is the first section, which landscape oriented with vertically centered text.");
// If we start a new section using a document builder,
// it will inherit the builder's current page setup properties.
builder->InsertBreak(BreakType::SectionBreakNewPage);
ASSERT_EQ(Orientation::Landscape, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Center, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
// We can revert its page setup properties to their default values using the "ClearFormatting" method.
builder->get_PageSetup()->ClearFormatting();
ASSERT_EQ(Orientation::Portrait, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Top, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
builder->Writeln(u"This is the second section, which is in default Letter paper size, portrait orientation and top alignment.");
doc->Save(ArtifactsDir + u"PageSetup.ClearFormatting.docx");
Enumerator
Bottom 

Text is aligned at the bottom of the page.

Center 

Text is aligned in the middle of the page.

Justify 

Text is spread to fill the page.

Top 

Text is aligned at the top of the page.

◆ PaperSize

Specifies paper size.

Examples

Shows how to adjust paper size, orientation, margins, along with other settings for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_PageSetup()->set_PaperSize(PaperSize::Legal);
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_TopMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_BottomMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_LeftMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_RightMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_HeaderDistance(ConvertUtil::InchToPoint(0.2));
builder->get_PageSetup()->set_FooterDistance(ConvertUtil::InchToPoint(0.2));
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PageSetup.PageMargins.docx");

Shows how to set page sizes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// We can change the current page's size to a pre-defined size
// by using the "PaperSize" property of this section's PageSetup object.
builder->get_PageSetup()->set_PaperSize(PaperSize::Tabloid);
ASPOSE_ASSERT_EQ(792.0, builder->get_PageSetup()->get_PageWidth());
ASPOSE_ASSERT_EQ(1224.0, builder->get_PageSetup()->get_PageHeight());
builder->Writeln(String::Format(u"This page is {0}x{1}.", builder->get_PageSetup()->get_PageWidth(), builder->get_PageSetup()->get_PageHeight()));
// Each section has its own PageSetup object. When we use a document builder to make a new section,
// that section's PageSetup object inherits all the previous section's PageSetup object's values.
builder->InsertBreak(BreakType::SectionBreakEvenPage);
ASSERT_EQ(PaperSize::Tabloid, builder->get_PageSetup()->get_PaperSize());
builder->get_PageSetup()->set_PaperSize(PaperSize::A5);
builder->Writeln(String::Format(u"This page is {0}x{1}.", builder->get_PageSetup()->get_PageWidth(), builder->get_PageSetup()->get_PageHeight()));
ASPOSE_ASSERT_EQ(419.55, builder->get_PageSetup()->get_PageWidth());
ASPOSE_ASSERT_EQ(595.30, builder->get_PageSetup()->get_PageHeight());
builder->InsertBreak(BreakType::SectionBreakEvenPage);
// Set a custom size for this section's pages.
builder->get_PageSetup()->set_PageWidth(620);
builder->get_PageSetup()->set_PageHeight(480);
ASSERT_EQ(PaperSize::Custom, builder->get_PageSetup()->get_PaperSize());
builder->Writeln(String::Format(u"This page is {0}x{1}.", builder->get_PageSetup()->get_PageWidth(), builder->get_PageSetup()->get_PageHeight()));
doc->Save(ArtifactsDir + u"PageSetup.PaperSizes.docx");

Shows how to construct an Aspose.Words document by hand.

auto doc = MakeObject<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.
auto section = MakeObject<Section>(doc);
doc->AppendChild(section);
// Set some page setup properties for the section.
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(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.
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
// Create a paragraph, set some formatting properties, and then append it as a child to the body.
auto para = MakeObject<Paragraph>(doc);
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(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.
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello World!");
run->get_Font()->set_Color(System::Drawing::Color::get_Red());
para->AppendChild(run);
ASSERT_EQ(u"Hello World!", doc->GetText().Trim());
doc->Save(ArtifactsDir + u"Section.CreateManually.docx");
Enumerator
A3 

297 x 420 mm.

A4 

210 x 297 mm.

A5 

148 x 210 mm.

B4 

250 x 353 mm.

B5 

176 x 250 mm.

Executive 

7.25 x 10.5 inches.

Folio 

8.5 x 13 inches.

Ledger 

17 x 11 inches.

Legal 

8.5 x 14 inches.

Letter 

8.5 x 11 inches.

EnvelopeDL 

110 x 220 mm.

Quarto 

8.47 x 10.83 inches.

Statement 

8.5 x 5.5 inches.

Tabloid 

11 x 17 inches.

Paper10x14 

10 x 14 inches.

Paper11x17 

11 x 17 inches.

Custom 

Custom paper size.

◆ ParagraphAlignment

Specifies text alignment in a paragraph.

Examples

Shows how to construct an Aspose.Words document by hand.

auto doc = MakeObject<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.
auto section = MakeObject<Section>(doc);
doc->AppendChild(section);
// Set some page setup properties for the section.
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(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.
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
// Create a paragraph, set some formatting properties, and then append it as a child to the body.
auto para = MakeObject<Paragraph>(doc);
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(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.
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello World!");
run->get_Font()->set_Color(System::Drawing::Color::get_Red());
para->AppendChild(run);
ASSERT_EQ(u"Hello World!", doc->GetText().Trim());
doc->Save(ArtifactsDir + u"Section.CreateManually.docx");
Enumerator
Left 

Text is aligned to the left.

Center 

Text is centered horizontally.

Right 

Text is aligned to the right.

Justify 

Text is aligned to both left and right.

Distributed 

Text is evenly distributed.

ArabicMediumKashida 

Arabic only. Kashida length for text is extended to a medium length determined by the consumer.

ArabicHighKashida 

Arabic only. Kashida length for text is extended to its widest possible length.

ArabicLowKashida 

Arabic only. Kashida length for text is extended to a slightly longer length.

ThaiDistributed 

Thai only. Text is justified with an optimization for Thai.

◆ ProtectionType

Protection type for a document.

Examples

Shows how to turn off protection for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Section 1. Hello world!");
builder->InsertBreak(BreakType::SectionBreakNewPage);
builder->Writeln(u"Section 2. Hello again!");
builder->Write(u"Please enter text here: ");
builder->InsertTextInput(u"TextInput1", TextFormFieldType::Regular, u"", u"Placeholder text", 0);
// Apply write protection to every section in the document.
// Turn off write protection for the first section.
doc->get_Sections()->idx_get(0)->set_ProtectedForForms(false);
// In this output document, we will be able to edit the first section freely,
// and we will only be able to edit the contents of the form field in the second section.
doc->Save(ArtifactsDir + u"Section.Protect.docx");
Enumerator
AllowOnlyComments 

User can only modify comments in the document.

AllowOnlyFormFields 

User can only enter data in the form fields in the document.

AllowOnlyRevisions 

User can only add revision marks to the document.

ReadOnly 

No changes are allowed to the document. Available since Microsoft Word 2003.

NoProtection 

The document is not protected.

◆ RevisionsView

Allows to specify whether to work with the original or revised version of a document.

Examples

Shows how to switch between the revised and the original view of a document.

auto doc = MakeObject<Document>(MyDir + u"Revisions at list levels.docx");
doc->UpdateListLabels();
SharedPtr<ParagraphCollection> paragraphs = doc->get_FirstSection()->get_Body()->get_Paragraphs();
ASSERT_EQ(u"1.", paragraphs->idx_get(0)->get_ListLabel()->get_LabelString());
ASSERT_EQ(u"a.", paragraphs->idx_get(1)->get_ListLabel()->get_LabelString());
ASSERT_EQ(String::Empty, paragraphs->idx_get(2)->get_ListLabel()->get_LabelString());
// View the document object as if all the revisions are accepted. Currently supports list labels.
doc->set_RevisionsView(RevisionsView::Final);
ASSERT_EQ(String::Empty, paragraphs->idx_get(0)->get_ListLabel()->get_LabelString());
ASSERT_EQ(u"1.", paragraphs->idx_get(1)->get_ListLabel()->get_LabelString());
ASSERT_EQ(u"a.", paragraphs->idx_get(2)->get_ListLabel()->get_LabelString());
Enumerator
Original 

Specifies original version of a document.

Final 

Specifies revised version of a document.

◆ RevisionType

Specifies the type of change being tracked in Revision.

Examples

Shows how to work with revisions in a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Normal editing of the document does not count as a revision.
builder->Write(u"This does not count as a revision. ");
ASSERT_FALSE(doc->get_HasRevisions());
// To register our edits as revisions, we need to declare an author, and then start tracking them.
doc->StartTrackRevisions(u"John Doe", System::DateTime::get_Now());
builder->Write(u"This is revision #1. ");
ASSERT_TRUE(doc->get_HasRevisions());
ASSERT_EQ(1, doc->get_Revisions()->get_Count());
// This flag corresponds to the "Review" -> "Tracking" -> "Track Changes" option in Microsoft Word.
// The "StartTrackRevisions" method does not affect its value,
// and the document is tracking revisions programmatically despite it having a value of "false".
// If we open this document using Microsoft Word, it will not be tracking revisions.
ASSERT_FALSE(doc->get_TrackRevisions());
// We have added text using the document builder, so the first revision is an insertion-type revision.
SharedPtr<Revision> revision = doc->get_Revisions()->idx_get(0);
ASSERT_EQ(u"John Doe", revision->get_Author());
ASSERT_EQ(u"This is revision #1. ", revision->get_ParentNode()->GetText());
ASSERT_EQ(RevisionType::Insertion, revision->get_RevisionType());
ASSERT_EQ(revision->get_DateTime().get_Date(), System::DateTime::get_Now().get_Date());
ASPOSE_ASSERT_EQ(doc->get_Revisions()->get_Groups()->idx_get(0), revision->get_Group());
// Remove a run to create a deletion-type revision.
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_Runs()->idx_get(0)->Remove();
// Adding a new revision places it at the beginning of the revision collection.
ASSERT_EQ(RevisionType::Deletion, doc->get_Revisions()->idx_get(0)->get_RevisionType());
ASSERT_EQ(2, doc->get_Revisions()->get_Count());
// Insert revisions show up in the document body even before we accept/reject the revision.
// Rejecting the revision will remove its nodes from the body. Conversely, nodes that make up delete revisions
// also linger in the document until we accept the revision.
ASSERT_EQ(u"This does not count as a revision. This is revision #1.", doc->GetText().Trim());
// Accepting the delete revision will remove its parent node from the paragraph text
// and then remove the collection's revision itself.
doc->get_Revisions()->idx_get(0)->Accept();
ASSERT_EQ(1, doc->get_Revisions()->get_Count());
ASSERT_EQ(u"This is revision #1.", doc->GetText().Trim());
builder->Writeln(u"");
builder->Write(u"This is revision #2.");
// Now move the node to create a moving revision type.
SharedPtr<Node> node = doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(1);
SharedPtr<Node> endNode = doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(1)->get_NextSibling();
SharedPtr<Node> referenceNode = doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(0);
while (node != endNode)
{
SharedPtr<Node> nextNode = node->get_NextSibling();
doc->get_FirstSection()->get_Body()->InsertBefore(node, referenceNode);
node = nextNode;
}
ASSERT_EQ(RevisionType::Moving, doc->get_Revisions()->idx_get(0)->get_RevisionType());
ASSERT_EQ(8, doc->get_Revisions()->get_Count());
ASSERT_EQ(u"This is revision #2.\rThis is revision #1. \rThis is revision #2.", doc->GetText().Trim());
// The moving revision is now at index 1. Reject the revision to discard its contents.
doc->get_Revisions()->idx_get(1)->Reject();
ASSERT_EQ(6, doc->get_Revisions()->get_Count());
ASSERT_EQ(u"This is revision #1. \rThis is revision #2.", doc->GetText().Trim());
Enumerator
Insertion 

New content was inserted in the document.

Deletion 

Content was removed from the document.

FormatChange 

Change of formatting was applied to the parent node.

StyleDefinitionChange 

Change of formatting was applied to the parent style.

Moving 

Content was moved in the document.

◆ RunPrExpandFlags

RunPrExpandFlags enumeration.

Enumerator
Normal 
DocumentDefaults 
IgnoreNormalFontSize 
IgnoreHyperlinkCharStyle 
Revised 
AfterChanges 
GlobalDefaults 
NoTableStyle 
NoDirectFormatting 
NoParaStyle 
NoChangeCommentSize 
Layout 

◆ SaveFormat

Indicates the format in which the document is saved.

See also
Aspose::Words::Document::Save(System::SharedPtr<System::IO::Stream>, Aspose::Words::SaveFormat)
Aspose::Words::Saving::SaveOptions
Examples

Shows how to convert from DOCX to HTML format.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
doc->Save(ArtifactsDir + u"Document.ConvertToHtml.html", SaveFormat::Html);
Enumerator
Unknown 

Default, invalid value for file format.

Doc 

Saves the document in the Microsoft Word 97 - 2007 Document format.

Dot 

Saves the document in the Microsoft Word 97 - 2007 Template format.

Docx 

Saves the document as an Office Open XML WordprocessingML Document (macro-free).

Docm 

Saves the document as an Office Open XML WordprocessingML Macro-Enabled Document.

Dotx 

Saves the document as an Office Open XML WordprocessingML Template (macro-free).

Dotm 

Saves the document as an Office Open XML WordprocessingML Macro-Enabled Template.

FlatOpc 

Saves the document as an Office Open XML WordprocessingML stored in a flat XML file instead of a ZIP package.

FlatOpcMacroEnabled 

Saves the document as an Office Open XML WordprocessingML Macro-Enabled Document stored in a flat XML file instead of a ZIP package.

FlatOpcTemplate 

Saves the document as an Office Open XML WordprocessingML Template (macro-free) stored in a flat XML file instead of a ZIP package.

FlatOpcTemplateMacroEnabled 

Saves the document as an Office Open XML WordprocessingML Macro-Enabled Template stored in a flat XML file instead of a ZIP package.

Rtf 

Saves the document in the RTF format. All characters above 7-bits are escaped as hexadecimal or Unicode characters.

WordML 

Saves the document in the Microsoft Word 2003 WordprocessingML format.

Pdf 

Saves the document as PDF (Adobe Portable Document) format.

Xps 

Saves the document in the XPS (XML Paper Specification) format.

XamlFixed 

Saves the document in the Extensible Application Markup Language (XAML) format as a fixed document.

Svg 

Saves the document in the Svg (Scalable Vector Graphics) format.

HtmlFixed 

Saves the document in the HTML format using absolutely positioned elements.

OpenXps 

Saves the document in the OpenXPS (Ecma-388) format.

Ps 

Saves the document in the PS (PostScript) format.

Pcl 

Saves the document in the PCL (Printer Control Language) format.

Html 

Saves the document in the HTML format.

Mhtml 

Saves the document in the MHTML (Web archive) format.

Epub 

Saves the document in the IDPF EPUB format.

Odt 

Saves the document as an ODF Text Document.

Ott 

Saves the document as an ODF Text Document Template.

Text 

Saves the document in the plain text format.

XamlFlow 

Beta. Saves the document in the Extensible Application Markup Language (XAML) format as a flow document.

XamlFlowPack 

Beta. Saves the document in the Extensible Application Markup Language (XAML) package format as a flow document.

Markdown 

Saves the document in the Markdown format.

Tiff 

Renders a page or pages of the document and saves them into a single or multipage TIFF file.

Png 

Renders a page of the document and saves it as a PNG file.

Bmp 

Renders a page of the document and saves it as a BMP file.

Emf 

Renders a page of the document and saves it as a vector EMF (Enhanced Meta File) file.

Jpeg 

Renders a page of the document and saves it as a JPEG file.

Gif 

Renders a page of the document and saves it as a GIF file.

◆ SectionLayoutMode

Specifies the layout mode for a section allowing to define the document grid behavior.

Examples

Shows how to specify a for the number of characters that each line may have.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Enable pitching, and then use it to set the number of characters per line in this section.
builder->get_PageSetup()->set_LayoutMode(SectionLayoutMode::Grid);
builder->get_PageSetup()->set_CharactersPerLine(10);
// The number of characters also depends on the size of the font.
doc->get_Styles()->idx_get(u"Normal")->get_Font()->set_Size(20);
ASSERT_EQ(8, doc->get_FirstSection()->get_PageSetup()->get_CharactersPerLine());
builder->Writeln(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
doc->Save(ArtifactsDir + u"PageSetup.CharactersPerLine.docx");

Shows how to specify a limit for the number of lines that each page may have.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Enable pitching, and then use it to set the number of lines per page in this section.
// A large enough font size will push some lines down onto the next page to avoid overlapping characters.
builder->get_PageSetup()->set_LayoutMode(SectionLayoutMode::LineGrid);
builder->get_PageSetup()->set_LinesPerPage(15);
builder->get_ParagraphFormat()->set_SnapToGrid(true);
for (int i = 0; i < 30; i++)
{
builder->Write(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ");
}
doc->Save(ArtifactsDir + u"PageSetup.LinesPerPage.docx");
Enumerator
Default 

Specifies that no document grid shall be applied to the contents of the corresponding section in the document.

Grid 

Specifies that the corresponding section shall have both the additional line pitch and character pitch added to each line and character within it in order to maintain a specific number of lines per page and characters per line. Characters will not be automatically aligned with gridlines on typing.

LineGrid 

Specifies that the corresponding section shall have additional line pitch added to each line within it in order to maintain the specified number of lines per page.

SnapToChars 

Specifies that the corresponding section shall have both the additional line pitch and character pitch added to each line and character within it in order to maintain a specific number of lines per page and characters per line. Characters will be automatically aligned with gridlines on typing.

◆ SectionStart

The type of break at the beginning of the section.

Examples

Shows how to specify how a new section separates itself from the previous.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"This text is in section 1.");
// Section break types determine how a new section separates itself from the previous section.
// Below are five types of section breaks.
// 1 - Starts the next section on a new page:
builder->InsertBreak(BreakType::SectionBreakNewPage);
builder->Writeln(u"This text is in section 2.");
ASSERT_EQ(SectionStart::NewPage, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_SectionStart());
// 2 - Starts the next section on the current page:
builder->InsertBreak(BreakType::SectionBreakContinuous);
builder->Writeln(u"This text is in section 3.");
ASSERT_EQ(SectionStart::Continuous, doc->get_Sections()->idx_get(2)->get_PageSetup()->get_SectionStart());
// 3 - Starts the next section on a new even page:
builder->InsertBreak(BreakType::SectionBreakEvenPage);
builder->Writeln(u"This text is in section 4.");
ASSERT_EQ(SectionStart::EvenPage, doc->get_Sections()->idx_get(3)->get_PageSetup()->get_SectionStart());
// 4 - Starts the next section on a new odd page:
builder->InsertBreak(BreakType::SectionBreakOddPage);
builder->Writeln(u"This text is in section 5.");
ASSERT_EQ(SectionStart::OddPage, doc->get_Sections()->idx_get(4)->get_PageSetup()->get_SectionStart());
// 5 - Starts the next section on a new column:
SharedPtr<TextColumnCollection> columns = builder->get_PageSetup()->get_TextColumns();
columns->SetCount(2);
builder->InsertBreak(BreakType::SectionBreakNewColumn);
builder->Writeln(u"This text is in section 6.");
ASSERT_EQ(SectionStart::NewColumn, doc->get_Sections()->idx_get(5)->get_PageSetup()->get_SectionStart());
doc->Save(ArtifactsDir + u"PageSetup.SetSectionStart.docx");

Shows how to construct an Aspose.Words document by hand.

auto doc = MakeObject<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.
auto section = MakeObject<Section>(doc);
doc->AppendChild(section);
// Set some page setup properties for the section.
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(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.
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
// Create a paragraph, set some formatting properties, and then append it as a child to the body.
auto para = MakeObject<Paragraph>(doc);
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(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.
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello World!");
run->get_Font()->set_Color(System::Drawing::Color::get_Red());
para->AppendChild(run);
ASSERT_EQ(u"Hello World!", doc->GetText().Trim());
doc->Save(ArtifactsDir + u"Section.CreateManually.docx");
Enumerator
Continuous 

The new section starts on the same page as the previous section.

NewColumn 

The section starts from a new column.

NewPage 

The section starts from a new page.

EvenPage 

The section starts on a new even page.

OddPage 

The section starts on a new odd page.

◆ StoryType

Text of a Word document is stored in stories. StoryType identifies a story.

Examples

Shows how to remove all shapes from a node.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a DocumentBuilder to insert a shape. This is an inline shape,
// which has a parent Paragraph, which is a child node of the first section's Body.
builder->InsertShape(ShapeType::Cube, 100.0, 100.0);
ASSERT_EQ(1, doc->GetChildNodes(NodeType::Shape, true)->get_Count());
// We can delete all shapes from the child paragraphs of this Body.
ASSERT_EQ(StoryType::MainText, doc->get_FirstSection()->get_Body()->get_StoryType());
doc->get_FirstSection()->get_Body()->DeleteShapes();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::Shape, true)->get_Count());
Enumerator
None 

Default value. There is no such story in the document.

MainText 

Contains the main text of the document, represented by Body.

Footnotes 

Contains footnote text, represented by Footnote.

Endnotes 

Contains endnotes text, represented by Footnote.

Comments 

Contains document comments (annotations), represented by Comment.

Textbox 

Contains shape or textbox text, represented by Shape.

EvenPagesHeader 

Contains text of the even pages header, represented by HeaderFooter.

PrimaryHeader 

Contains text of the primary header. When header is different for odd and even pages, contains text of the odd pages header. Represented by HeaderFooter.

EvenPagesFooter 

Contains text of the even pages footer, represented by HeaderFooter.

PrimaryFooter 

Contains text of the primary footer. When footer is different for odd and even pages, contains text of the odd pages footer. Represented by HeaderFooter.

FirstPageHeader 

Contains text of the first page header, represented by HeaderFooter.

FirstPageFooter 

Contains text of the first page footer, represented by HeaderFooter.

FootnoteSeparator 

Contains the text of the footnote separator, represented by FootnoteSeparator.

FootnoteContinuationSeparator 

Contains the text of the footnote continuation separator, represented by FootnoteSeparator.

FootnoteContinuationNotice 

Contains the text of the footnote continuation notice separator, represented by FootnoteSeparator.

EndnoteSeparator 

Contains the text of the endnote separator, represented by FootnoteSeparator.

EndnoteContinuationSeparator 

Contains the text of the endnote continuation separator, represented by FootnoteSeparator.

EndnoteContinuationNotice 

Contains the text of the endnote continuation notice separator, represented by FootnoteSeparator.

◆ StyleIdentifier

Locale independent style identifier.

The names of built-in styles in MS Word are localized for different languages. Using a style identifier you can find the correct style regardless of the document language.

All user defined styles are assigned the StyleIdentifier.User value.

Examples

Shows how to change the style of existing text.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Below are two ways of referencing styles.
// 1 - Using the style name:
builder->get_Font()->set_StyleName(u"Emphasis");
builder->Writeln(u"Text originally in \"Emphasis\" style");
// 2 - Using a built-in style identifier:
builder->get_Font()->set_StyleIdentifier(StyleIdentifier::IntenseEmphasis);
builder->Writeln(u"Text originally in \"Intense Emphasis\" style");
// Convert all uses of one style to another,
// using the above methods to reference old and new styles.
for (auto run : System::IterateOver(doc->GetChildNodes(NodeType::Run, true)->LINQ_OfType<SharedPtr<Run>>()))
{
if (run->get_Font()->get_StyleName() == u"Emphasis")
{
run->get_Font()->set_StyleName(u"Strong");
}
if (run->get_Font()->get_StyleIdentifier() == StyleIdentifier::IntenseEmphasis)
{
run->get_Font()->set_StyleIdentifier(StyleIdentifier::Strong);
}
}
doc->Save(ArtifactsDir + u"Font.ChangeStyle.docx");
Enumerator
BookTitle 
CommentReference 

The Annotation (Comment) Reference style.

DefaultParagraphFont 

The Default Paragraph Font style.

Emphasis 
EndnoteReference 

The Endnote Reference style.

FollowedHyperlink 
FootnoteReference 

The Footnote Reference style.

HtmlAcronym 
HtmlCite 
HtmlCode 
HtmlDefinition 
HtmlKeyboard 
HtmlSample 
HtmlTypewriter 
HtmlVariable 
Hyperlink 

The Hyperlink style.

IntenseEmphasis 
IntenseReference 
LineNumber 

The Line Number style.

PageNumber 

The Page Number style.

PlaceholderText 
SmartLink 

The Smart Link style.

Strong 
SubtleEmphasis 
SubtleReference 
BalloonText 
BodyText 

The Body Text style.

BodyText2 
BodyText3 
BodyText1I 
BodyText1I2 
BodyTextInd 
BodyTextInd2 
BodyTextInd3 
Closing 
CommentSubject 
CommentText 

The Annotation (Comment) Text style.

Date 
DocumentMap 
EmailSignature 
EndnoteText 

The Endnote Text style.

Footer 

The Footer style.

FootnoteText 

The Footnote Text style.

Header 

The Header style.

Heading1 

The Heading 1 style.

Heading2 

The Heading 2 style.

Heading3 

The Heading 3 style.

Heading4 

The Heading 4 style.

Heading5 

The Heading 5 style.

Heading6 

The Heading 6 style.

Heading7 

The Heading 7 style.

Heading8 

The Heading 8 style.

Heading9 

The Heading 9 style.

HtmlAddress 
HtmlTopOfForm 
HtmlBottomOfForm 
HtmlPreformatted 
IntenseQuote 
Macro 
MessageHeader 
NoteHeading 
PlainText 
Quote 
Salutation 
Signature 
Subtitle 
Title 

The Title style.

Bibliography 
BlockText 
Caption 
EnvelopeAddress 

The Envelope Address style.

EnvelopeReturn 

The Envelope Return style.

Index1 
Index2 
Index3 
Index4 
Index5 
Index6 
Index7 
Index8 
Index9 
IndexHeading 

The Index Heading style.

List 

The List style.

List2 
List3 
List4 
List5 
ListBullet 

The List Bullet style.

ListBullet2 
ListBullet3 
ListBullet4 
ListBullet5 
ListContinue 
ListContinue2 
ListContinue3 
ListContinue4 
ListContinue5 
ListNumber 

The List Number style.

ListNumber2 
ListNumber3 
ListNumber4 
ListNumber5 
ListParagraph 
NoSpacing 
Normal 

The Normal style.

NormalWeb 
NormalIndent 

The Normal Indent style.

TableOfAuthorities 
TableOfFigures 

The Table of Figures style.

ToaHeading 
Toc1 
Toc2 
Toc3 
Toc4 
Toc5 
Toc6 
Toc7 
Toc8 
Toc9 
TocHeading 
Revision 
OutlineList1 

The 1 / a / i style.

OutlineList2 

The 1 / 1.1 / 1.1.1 style.

OutlineList3 

The Article / Section style.

NoList 
ColorfulGrid 
ColorfulGridAccent1 
ColorfulGridAccent2 
ColorfulGridAccent3 
ColorfulGridAccent4 
ColorfulGridAccent5 
ColorfulGridAccent6 
ColorfulList 
ColorfulListAccent1 
ColorfulListAccent2 
ColorfulListAccent3 
ColorfulListAccent4 
ColorfulListAccent5 
ColorfulListAccent6 
ColorfulShading 
ColorfulShadingAccent1 
ColorfulShadingAccent2 
ColorfulShadingAccent3 
ColorfulShadingAccent4 
ColorfulShadingAccent5 
ColorfulShadingAccent6 
DarkList 
DarkListAccent1 
DarkListAccent2 
DarkListAccent3 
DarkListAccent4 
DarkListAccent5 
DarkListAccent6 
LightGrid 
LightGridAccent1 
LightGridAccent2 
LightGridAccent3 
LightGridAccent4 
LightGridAccent5 
LightGridAccent6 
LightList 
LightListAccent1 
LightListAccent2 
LightListAccent3 
LightListAccent4 
LightListAccent5 
LightListAccent6 
LightShading 
LightShadingAccent1 
LightShadingAccent2 
LightShadingAccent3 
LightShadingAccent4 
LightShadingAccent5 
LightShadingAccent6 
MediumGrid1 
MediumGrid1Accent1 
MediumGrid1Accent2 
MediumGrid1Accent3 
MediumGrid1Accent4 
MediumGrid1Accent5 
MediumGrid1Accent6 
MediumGrid2 
MediumGrid2Accent1 
MediumGrid2Accent2 
MediumGrid2Accent3 
MediumGrid2Accent4 
MediumGrid2Accent5 
MediumGrid2Accent6 
MediumGrid3 
MediumGrid3Accent1 
MediumGrid3Accent2 
MediumGrid3Accent3 
MediumGrid3Accent4 
MediumGrid3Accent5 
MediumGrid3Accent6 
MediumList1 
MediumList1Accent1 
MediumList1Accent2 
MediumList1Accent3 
MediumList1Accent4 
MediumList1Accent5 
MediumList1Accent6 
MediumList2 
MediumList2Accent1 
MediumList2Accent2 
MediumList2Accent3 
MediumList2Accent4 
MediumList2Accent5 
MediumList2Accent6 
MediumShading1 
MediumShading1Accent1 
MediumShading1Accent2 
MediumShading1Accent3 
MediumShading1Accent4 
MediumShading1Accent5 
MediumShading1Accent6 
MediumShading2 
MediumShading2Accent1 
MediumShading2Accent2 
MediumShading2Accent3 
MediumShading2Accent4 
MediumShading2Accent5 
MediumShading2Accent6 
Table3DEffects1 
Table3DEffects2 
Table3DEffects3 
TableClassic1 
TableClassic2 
TableClassic3 
TableClassic4 
TableColorful1 
TableColorful2 
TableColorful3 
TableColumns1 
TableColumns2 
TableColumns3 
TableColumns4 
TableColumns5 
TableContemporary 
TableElegant 
TableGrid 
TableGrid1 
TableGrid2 
TableGrid3 
TableGrid4 
TableGrid5 
TableGrid6 
TableGrid7 
TableGrid8 
TableList1 
TableList2 
TableList3 
TableList4 
TableList5 
TableList6 
TableList7 
TableList8 
TableNormal 
TableProfessional 
TableSimple1 
TableSimple2 
TableSimple3 
TableSubtle1 
TableSubtle2 
TableTheme 
TableWeb1 
TableWeb2 
TableWeb3 
PlainTable1 

Plain Table 1.

PlainTable2 

Plain Table 2.

PlainTable3 

Plain Table 3.

PlainTable4 

Plain Table 4.

PlainTable5 

Plain Table 5.

TableGridLight 

Table Grid Light.

GridTable1Light 

Grid Table 1 Light.

GridTable2 

Grid Table 2.

GridTable3 

Grid Table 3.

GridTable4 

Grid Table 4.

GridTable5Dark 

Grid Table 5 Dark.

GridTable6Colorful 

Grid Table 6 Colorful.

GridTable7Colorful 

Grid Table 7 Colorful.

GridTable1LightAccent1 

Grid Table 1 Light - Accent 1.

GridTable2Accent1 

Grid Table 2 - Accent 1.

GridTable3Accent1 

Grid Table 3 - Accent 1.

GridTable4Accent1 

Grid Table 4 - Accent 1.

GridTable5DarkAccent1 

Grid Table 5 Dark - Accent 1.

GridTable6ColorfulAccent1 

Grid Table 6 Colorful - Accent 1.

GridTable7ColorfulAccent1 

Grid Table 7 Colorful - Accent 1.

GridTable1LightAccent2 

Grid Table 1 Light - Accent 2.

GridTable2Accent2 

Grid Table 2 - Accent 2.

GridTable3Accent2 

Grid Table 3 - Accent 2.

GridTable4Accent2 

Grid Table 4 - Accent 2.

GridTable5DarkAccent2 

Grid Table 5 Dark - Accent 2.

GridTable6ColorfulAccent2 

Grid Table 6 Colorful - Accent 2.

GridTable7ColorfulAccent2 

Grid Table 7 Colorful - Accent 2.

GridTable1LightAccent3 

Grid Table 1 Light - Accent 3.

GridTable2Accent3 

Grid Table 2 - Accent 3.

GridTable3Accent3 

Grid Table 3 - Accent 3.

GridTable4Accent3 

Grid Table 4 - Accent 3.

GridTable5DarkAccent3 

Grid Table 5 Dark - Accent 3.

GridTable6ColorfulAccent3 

Grid Table 6 Colorful - Accent 3.

GridTable7ColorfulAccent3 

Grid Table 7 Colorful - Accent 3.

GridTable1LightAccent4 

Grid Table 1 Light - Accent 4.

GridTable2Accent4 

Grid Table 2 - Accent 4.

GridTable3Accent4 

Grid Table 3 - Accent 4.

GridTable4Accent4 

Grid Table 4 - Accent 4.

GridTable5DarkAccent4 

Grid Table 5 Dark - Accent 4.

GridTable6ColorfulAccent4 

Grid Table 6 Colorful - Accent 4.

GridTable7ColorfulAccent4 

Grid Table 7 Colorful - Accent 4.

GridTable1LightAccent5 

Grid Table 1 Light - Accent 5.

GridTable2Accent5 

Grid Table 2 - Accent 5.

GridTable3Accent5 

Grid Table 3 - Accent 5.

GridTable4Accent5 

Grid Table 4 - Accent 5.

GridTable5DarkAccent5 

Grid Table 5 Dark - Accent 5.

GridTable6ColorfulAccent5 

Grid Table 6 Colorful - Accent 5.

GridTable7ColorfulAccent5 

Grid Table 7 Colorful - Accent 5.

GridTable1LightAccent6 

Grid Table 1 Light - Accent 6.

GridTable2Accent6 

Grid Table 2 - Accent 6.

GridTable3Accent6 

Grid Table 3 - Accent 6.

GridTable4Accent6 

Grid Table 4 - Accent 6.

GridTable5DarkAccent6 

Grid Table 5 Dark - Accent 6.

GridTable6ColorfulAccent6 

Grid Table 6 Colorful - Accent 6.

GridTable7ColorfulAccent6 

Grid Table 7 Colorful - Accent 6.

ListTable1Light 

List Table 1 Light.

ListTable2 

List Table 2.

ListTable3 

List Table 3.

ListTable4 

List Table 4.

ListTable5Dark 

List Table 5 Dark.

ListTable6Colorful 

List Table 6 Colorful.

ListTable7Colorful 

List Table 7 Colorful.

ListTable1LightAccent1 

List Table 1 Light - Accent 1.

ListTable2Accent1 

List Table 2 - Accent 1.

ListTable3Accent1 

List Table 3 - Accent 1.

ListTable4Accent1 

List Table 4 - Accent 1.

ListTable5DarkAccent1 

List Table 5 Dark - Accent 1.

ListTable6ColorfulAccent1 

List Table 6 Colorful - Accent 1.

ListTable7ColorfulAccent1 

List Table 7 Colorful - Accent 1.

ListTable1LightAccent2 

List Table 1 Light - Accent 2.

ListTable2Accent2 

List Table 2 - Accent 2.

ListTable3Accent2 

List Table 3 - Accent 2.

ListTable4Accent2 

List Table 4 - Accent 2.

ListTable5DarkAccent2 

List Table 5 Dark - Accent 2.

ListTable6ColorfulAccent2 

List Table 6 Colorful - Accent 2.

ListTable7ColorfulAccent2 

List Table 7 Colorful - Accent 2.

ListTable1LightAccent3 

List Table 1 Light - Accent 3.

ListTable2Accent3 

List Table 2 - Accent 3.

ListTable3Accent3 

List Table 3 - Accent 3.

ListTable4Accent3 

List Table 4 - Accent 3.

ListTable5DarkAccent3 

List Table 5 Dark - Accent 3.

ListTable6ColorfulAccent3 

List Table 6 Colorful - Accent 3.

ListTable7ColorfulAccent3 

List Table 7 Colorful - Accent 3.

ListTable1LightAccent4 

List Table 1 Light - Accent 4.

ListTable2Accent4 

List Table 2 - Accent 4.

ListTable3Accent4 

List Table 3 - Accent 4.

ListTable4Accent4 

List Table 4 - Accent 4.

ListTable5DarkAccent4 

List Table 5 Dark - Accent 4.

ListTable6ColorfulAccent4 

List Table 6 Colorful - Accent 4.

ListTable7ColorfulAccent4 

List Table 7 Colorful - Accent 4.

ListTable1LightAccent5 

List Table 1 Light - Accent 5.

ListTable2Accent5 

List Table 2 - Accent 5.

ListTable3Accent5 

List Table 3 - Accent 5.

ListTable4Accent5 

List Table 4 - Accent 5.

ListTable5DarkAccent5 

List Table 5 Dark - Accent 5.

ListTable6ColorfulAccent5 

List Table 6 Colorful - Accent 5.

ListTable7ColorfulAccent5 

List Table 7 Colorful - Accent 5.

ListTable1LightAccent6 

List Table 1 Light - Accent 6.

ListTable2Accent6 

List Table 2 - Accent 6.

ListTable3Accent6 

List Table 3 - Accent 6.

ListTable4Accent6 

List Table 4 - Accent 6.

ListTable5DarkAccent6 

List Table 5 Dark - Accent 6.

ListTable6ColorfulAccent6 

List Table 6 Colorful - Accent 6.

ListTable7ColorfulAccent6 

List Table 7 Colorful - Accent 6.

User 

A user defined style.

Nil 

Reserved for internal use.

◆ StyleType

Represents type of the style.

Examples

Shows how to create a list style and use it in a document.

auto doc = MakeObject<Document>();
// A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
// We can create nested lists by increasing the indent level.
// We can begin and end a list by using a document builder's "ListFormat" property.
// Each paragraph that we add between a list's start and the end will become an item in the list.
// We can contain an entire List object within a style.
SharedPtr<Style> listStyle = doc->get_Styles()->Add(StyleType::List, u"MyListStyle");
SharedPtr<List> list1 = listStyle->get_List();
ASSERT_TRUE(list1->get_IsListStyleDefinition());
ASSERT_FALSE(list1->get_IsListStyleReference());
ASSERT_TRUE(list1->get_IsMultiLevel());
ASPOSE_ASSERT_EQ(listStyle, list1->get_Style());
// Change the appearance of all list levels in our list.
for (auto level : list1->get_ListLevels())
{
level->get_Font()->set_Name(u"Verdana");
level->get_Font()->set_Color(System::Drawing::Color::get_Blue());
level->get_Font()->set_Bold(true);
}
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Using list style first time:");
// Create another list from a list within a style.
SharedPtr<List> list2 = doc->get_Lists()->Add(listStyle);
ASSERT_FALSE(list2->get_IsListStyleDefinition());
ASSERT_TRUE(list2->get_IsListStyleReference());
ASPOSE_ASSERT_EQ(listStyle, list2->get_Style());
// Add some list items that our list will format.
builder->get_ListFormat()->set_List(list2);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
builder->Writeln(u"Using list style second time:");
// Create and apply another list based on the list style.
SharedPtr<List> list3 = doc->get_Lists()->Add(listStyle);
builder->get_ListFormat()->set_List(list3);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
builder->get_Document()->Save(ArtifactsDir + u"Lists.CreateAndUseListStyle.docx");
Enumerator
Paragraph 

The style is a paragraph style.

Character 

The style is a character style.

Table 

The style is a table style.

List 

The style is a list style.

◆ TabAlignment

Specifies the alignment/type of a tab stop.

Enumerator
Left 

Left-aligns the text after the tab stop.

Center 

Centers the text around the tab stop.

Right 

Right-aligns the text at the tab stop.

Decimal 

Aligns the text at the decimal dot.

Bar 

Draws a vertical bar at the tab stop position.

List 

The tab is a delimiter between the number/bullet and text in a list item.

Clear 

Clears any tab stop in this position.

◆ TabLeader

Specifies the type of the leader line displayed under the tab character.

Enumerator
None 

No leader line is displayed.

Dots 

The leader line is made up from dots.

Dashes 

The leader line is made up from dashes.

Line 

The leader line is a single line.

Heavy 

The leader line is a single thick line.

MiddleDot 

The leader line is made up from middle-dots.

◆ TextDmlEffect

Dml text effect for text runs.

Enumerator
Glow 

Glow effect, in which a color blurred outline is added outside the edges of the object.

Fill 

Fill overlay effect.

Shadow 

Shadow effect.

Outline 

Outline effect.

Effect3D 

3D effect.

Reflection 

Reflection effect.

◆ TextEffect

Animation effect for text runs.

Enumerator
None 
LasVegasLights 
BlinkingBackground 
SparkleText 
MarchingBlackAnts 
MarchingRedAnts 
Shimmer 

◆ TextOrientation

Specifies orientation of text on a page, in a table cell or a text frame.

Examples

Shows how to build a formatted 2x2 table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->get_CellFormat()->set_VerticalAlignment(CellVerticalAlignment::Center);
builder->Write(u"Row 1, cell 1.");
builder->InsertCell();
builder->Write(u"Row 1, cell 2.");
builder->EndRow();
// While building the table, the document builder will apply its current RowFormat/CellFormat property values
// to the current row/cell that its cursor is in and any new rows/cells as it creates them.
ASSERT_EQ(CellVerticalAlignment::Center, table->get_Rows()->idx_get(0)->get_Cells()->idx_get(0)->get_CellFormat()->get_VerticalAlignment());
ASSERT_EQ(CellVerticalAlignment::Center, table->get_Rows()->idx_get(0)->get_Cells()->idx_get(1)->get_CellFormat()->get_VerticalAlignment());
builder->InsertCell();
builder->get_RowFormat()->set_Height(100);
builder->get_RowFormat()->set_HeightRule(HeightRule::Exactly);
builder->get_CellFormat()->set_Orientation(TextOrientation::Upward);
builder->Write(u"Row 2, cell 1.");
builder->InsertCell();
builder->get_CellFormat()->set_Orientation(TextOrientation::Downward);
builder->Write(u"Row 2, cell 2.");
builder->EndRow();
builder->EndTable();
// Previously added rows and cells are not retroactively affected by changes to the builder's formatting.
ASPOSE_ASSERT_EQ(0, table->get_Rows()->idx_get(0)->get_RowFormat()->get_Height());
ASSERT_EQ(HeightRule::Auto, table->get_Rows()->idx_get(0)->get_RowFormat()->get_HeightRule());
ASPOSE_ASSERT_EQ(100, table->get_Rows()->idx_get(1)->get_RowFormat()->get_Height());
ASSERT_EQ(HeightRule::Exactly, table->get_Rows()->idx_get(1)->get_RowFormat()->get_HeightRule());
ASSERT_EQ(TextOrientation::Upward, table->get_Rows()->idx_get(1)->get_Cells()->idx_get(0)->get_CellFormat()->get_Orientation());
ASSERT_EQ(TextOrientation::Downward, table->get_Rows()->idx_get(1)->get_Cells()->idx_get(1)->get_CellFormat()->get_Orientation());
doc->Save(ArtifactsDir + u"DocumentBuilder.BuildTable.docx");
Enumerator
Horizontal 

Text is arranged horizontally (lr-tb).

Downward 

Text is rotated 90 degrees to the right to appear from top to bottom (tb-rl).

Upward 

Text is rotated 90 degrees to the left to appear from bottom to top (bt-lr).

HorizontalRotatedFarEast 

Text is arranged horizontally, but Far East characters are rotated 90 degrees to the left (lr-tb-v).

VerticalFarEast 

Far East characters appear vertical, other text is rotated 90 degrees to the right to appear from top to bottom (tb-rl-v).

VerticalRotatedFarEast 

Far East characters appear vertical, other text is rotated 90 degrees to the right to appear from top to bottom vertically, then left to right horizontally (tb-lr-v).

◆ TextureIndex

Specifies shading texture.

Examples

Shows how to decorate text with borders and shading.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<BorderCollection> borders = builder->get_ParagraphFormat()->get_Borders();
borders->set_DistanceFromText(20);
borders->idx_get(BorderType::Left)->set_LineStyle(LineStyle::Double);
borders->idx_get(BorderType::Right)->set_LineStyle(LineStyle::Double);
borders->idx_get(BorderType::Top)->set_LineStyle(LineStyle::Double);
borders->idx_get(BorderType::Bottom)->set_LineStyle(LineStyle::Double);
SharedPtr<Shading> shading = builder->get_ParagraphFormat()->get_Shading();
shading->set_Texture(TextureIndex::TextureDiagonalCross);
shading->set_BackgroundPatternColor(System::Drawing::Color::get_LightCoral());
shading->set_ForegroundPatternColor(System::Drawing::Color::get_LightSalmon());
builder->Write(u"This paragraph is formatted with a double border and shading.");
doc->Save(ArtifactsDir + u"DocumentBuilder.ApplyBordersAndShading.docx");

Shows how to apply an outline border to a table.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
SharedPtr<Table> table = doc->get_FirstSection()->get_Body()->get_Tables()->idx_get(0);
// Align the table to the center of the page.
table->set_Alignment(TableAlignment::Center);
// Clear any existing borders and shading from the table.
table->ClearBorders();
table->ClearShading();
// Add green borders to the outline of the table.
// Fill the cells with a light green solid color.
doc->Save(ArtifactsDir + u"Table.SetOutlineBorders.docx");
Enumerator
Texture10Percent 
Texture12Pt5Percent 
Texture15Percent 
Texture17Pt5Percent 
Texture20Percent 
Texture22Pt5Percent 
Texture25Percent 
Texture27Pt5Percent 
Texture2Pt5Percent 
Texture30Percent 
Texture32Pt5Percent 
Texture35Percent 
Texture37Pt5Percent 
Texture40Percent 
Texture42Pt5Percent 
Texture45Percent 
Texture47Pt5Percent 
Texture50Percent 
Texture52Pt5Percent 
Texture55Percent 
Texture57Pt5Percent 
Texture5Percent 
Texture60Percent 
Texture62Pt5Percent 
Texture65Percent 
Texture67Pt5Percent 
Texture70Percent 
Texture72Pt5Percent 
Texture75Percent 
Texture77Pt5Percent 
Texture7Pt5Percent 
Texture80Percent 
Texture82Pt5Percent 
Texture85Percent 
Texture87Pt5Percent 
Texture90Percent 
Texture92Pt5Percent 
Texture95Percent 
Texture97Pt5Percent 
TextureCross 
TextureDarkCross 
TextureDarkDiagonalCross 
TextureDarkDiagonalDown 
TextureDarkDiagonalUp 
TextureDarkHorizontal 
TextureDarkVertical 
TextureDiagonalCross 
TextureDiagonalDown 
TextureDiagonalUp 
TextureHorizontal 
TextureNone 
TextureSolid 
TextureVertical 
TextureNil 

Specifies that there shall be no pattern used on the current shaded region (i.e. the pattern shall be a complete fill with the background color).

◆ Underline

Indicates type of the underline applied to a font.

Examples

Shows how to insert a hyperlink field.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Write(u"For more information, please visit the ");
// Insert a hyperlink and emphasize it with custom formatting.
// The hyperlink will be a clickable piece of text which will take us to the location specified in the URL.
builder->get_Font()->set_Color(System::Drawing::Color::get_Blue());
builder->get_Font()->set_Underline(Underline::Single);
builder->InsertHyperlink(u"Google website", u"https://www.google.com", false);
builder->get_Font()->ClearFormatting();
builder->Writeln(u".");
// Ctrl + left clicking the link in the text in Microsoft Word will take us to the URL via a new web browser window.
doc->Save(ArtifactsDir + u"DocumentBuilder.InsertHyperlink.docx");
Enumerator
None 
Single 
Words 
Double 
Dotted 
Thick 
Dash 
DashLong 
DotDash 
DotDotDash 
Wavy 
DottedHeavy 
DashHeavy 
DashLongHeavy 
DotDashHeavy 
DotDotDashHeavy 
WavyHeavy 
WavyDouble 

◆ VisitorAction

Allows the visitor to control the enumeration of nodes.

Enumerator
Continue 

The visitor requests the enumeration to continue.

SkipThisNode 

The visitor requests to skip the current node and continue enumeration.

Stop 

The visitor requests the enumeration of nodes to stop.

◆ WarningSource

Specifies the module that produces a warning during document loading or saving.

Enumerator
Unknown 

The warning source is not specified.

Layout 

Module that builds a document layout.

DrawingML 

Module that renders DrawingML shapes.

OfficeMath 

Module that renders OfficeMath.

Shapes 

Module that renders ordinary shapes.

Metafile 

Module that renders metafiles.

Xps 

Module that renders XPS.

Pdf 

Module that renders PDF.

Image 

Module that renders images.

Docx 

Module that reads/writes DOCX files.

Doc 

Module that reads/writes binary DOC files.

Text 

Module that reads/writes plaintext files.

Rtf 

Module that reads/writes RTF files.

WordML 

Module that reads/writes WML files.

Nrx 

Common modules that are shared between DOCX/WML reader/writer modules.

Odt 

Module that reads/writes ODT files.

Html 

Module that reads/writes HTML/MHTML files.

Validator 

Module that verifies model consistency and validity.

Xaml 

Module that reads/writes Xaml files.

Svm 

Module that reads Svm files.

MathML 

Module that reads W3C MathML files.

Font 

Module that reads font files.

Svg 

Module that reads SVG files.

Markdown 

Module that reads/writes Markdown files.

Chm 

Module that reads CHM files.

◆ WarningType

Specifies the type of a warning that is issued by Aspose.Words during document loading or saving.

Examples

Shows how to set the property for finding the closest match for a missing font from the available font sources.

void EnableFontSubstitution()
{
// Open a document that contains text formatted with a font that does not exist in any of our font sources.
auto doc = MakeObject<Document>(MyDir + u"Missing font.docx");
// Assign a callback for handling font substitution warnings.
auto substitutionWarningHandler = MakeObject<ExFontSettings::HandleDocumentSubstitutionWarnings>();
doc->set_WarningCallback(substitutionWarningHandler);
// Set a default font name and enable font substitution.
auto fontSettings = MakeObject<FontSettings>();
fontSettings->get_SubstitutionSettings()->get_DefaultFontSubstitution()->set_DefaultFontName(u"Arial");
;
fontSettings->get_SubstitutionSettings()->get_FontInfoSubstitution()->set_Enabled(true);
// We will get a font substitution warning if we save a document with a missing font.
doc->set_FontSettings(fontSettings);
doc->Save(ArtifactsDir + u"FontSettings.EnableFontSubstitution.pdf");
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<WarningInfo>>> warnings = substitutionWarningHandler->FontWarnings->GetEnumerator();
while (warnings->MoveNext())
{
std::cout << warnings->get_Current()->get_Description() << std::endl;
}
}
// We can also verify warnings in the collection and clear them.
ASSERT_EQ(WarningSource::Layout, substitutionWarningHandler->FontWarnings->idx_get(0)->get_Source());
ASSERT_EQ(u"Font '28 Days Later' has not been found. Using 'Calibri' font instead. Reason: alternative name from document.",
substitutionWarningHandler->FontWarnings->idx_get(0)->get_Description());
substitutionWarningHandler->FontWarnings->Clear();
ASSERT_EQ(0, substitutionWarningHandler->FontWarnings->get_Count());
}
class HandleDocumentSubstitutionWarnings : public IWarningCallback
{
public:
SharedPtr<WarningInfoCollection> FontWarnings;
void Warning(SharedPtr<WarningInfo> info) override
{
if (info->get_WarningType() == WarningType::FontSubstitution)
{
FontWarnings->Warning(info);
}
}
HandleDocumentSubstitutionWarnings() : FontWarnings(MakeObject<WarningInfoCollection>())
{
}
};
Enumerator
DataLossCategory 

Some text/char/image or other data will be missing from either the document tree following load, or from the created document following save.

DataLoss 

Generic data loss, no specific code.

MajorFormattingLossCategory 

The resulting document or a particular location in it might look substantially different compared to the original document.

MajorFormattingLoss 

Generic major formatting loss, no specific code.

MinorFormattingLossCategory 

The resulting document or a particular location in it might look somewhat different compared to the original document.

MinorFormattingLoss 

Generic minor formatting loss, no specific code.

FontSubstitution 

Font has been substituted.

FontEmbedding 

Loss of embedded font information during document saving.

UnexpectedContentCategory 

Some content in the source document could not be recognized (i.e. is unsupported), this may or may not cause issues or result in data/formatting loss.

UnexpectedContent 

Generic unexpected content, no specific code.

Hint 

Advises of a potential problem or suggests an improvement.

◆ WatermarkLayout

Defines layout of the watermark relative to the watermark center.

Examples

Shows how to create a text watermark.

auto doc = MakeObject<Document>();
// Add a plain text watermark.
doc->get_Watermark()->SetText(u"Aspose Watermark");
// If we wish to edit the text formatting using it as a watermark,
// we can do so by passing a TextWatermarkOptions object when creating the watermark.
auto textWatermarkOptions = MakeObject<TextWatermarkOptions>();
textWatermarkOptions->set_FontFamily(u"Arial");
textWatermarkOptions->set_FontSize(36.0f);
textWatermarkOptions->set_Color(System::Drawing::Color::get_Black());
textWatermarkOptions->set_Layout(WatermarkLayout::Diagonal);
textWatermarkOptions->set_IsSemitrasparent(false);
doc->get_Watermark()->SetText(u"Aspose Watermark", textWatermarkOptions);
doc->Save(ArtifactsDir + u"Document.TextWatermark.docx");
// We can remove a watermark from a document like this.
if (doc->get_Watermark()->get_Type() == WatermarkType::Text)
{
doc->get_Watermark()->Remove();
}
Enumerator
Horizontal 

Horizontal watermark layout. Corresponds to 0 degrees of rotation.

Diagonal 

Diagonal watermark layout. Corresponds to 315 degrees of rotation.

◆ WatermarkType

Specifies the watermark type.

Examples

Shows how to create a text watermark.

auto doc = MakeObject<Document>();
// Add a plain text watermark.
doc->get_Watermark()->SetText(u"Aspose Watermark");
// If we wish to edit the text formatting using it as a watermark,
// we can do so by passing a TextWatermarkOptions object when creating the watermark.
auto textWatermarkOptions = MakeObject<TextWatermarkOptions>();
textWatermarkOptions->set_FontFamily(u"Arial");
textWatermarkOptions->set_FontSize(36.0f);
textWatermarkOptions->set_Color(System::Drawing::Color::get_Black());
textWatermarkOptions->set_Layout(WatermarkLayout::Diagonal);
textWatermarkOptions->set_IsSemitrasparent(false);
doc->get_Watermark()->SetText(u"Aspose Watermark", textWatermarkOptions);
doc->Save(ArtifactsDir + u"Document.TextWatermark.docx");
// We can remove a watermark from a document like this.
if (doc->get_Watermark()->get_Type() == WatermarkType::Text)
{
doc->get_Watermark()->Remove();
}
Enumerator
Text 

Indicates that the text will be used as a watermark. Such a watermark corresponds to a WordArt object.

Image 

Indicates that the image will be used as a watermark. Such a watermark corresponds to a shape with image.

None 

Indicates watermark is no set.