Aspose::Words::ImportFormatOptions Class Reference

Detailed Description

Allows to specify various import options to format output.

Examples

Shows how to resolve duplicate styles while inserting documents.

auto dstDoc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(dstDoc);
SharedPtr<Style> myStyle = builder->get_Document()->get_Styles()->Add(StyleType::Paragraph, u"MyStyle");
myStyle->get_Font()->set_Size(14);
myStyle->get_Font()->set_Name(u"Courier New");
myStyle->get_Font()->set_Color(System::Drawing::Color::get_Blue());
builder->get_ParagraphFormat()->set_StyleName(myStyle->get_Name());
builder->Writeln(u"Hello world!");
// Clone the document and edit the clone's "MyStyle" style, so it is a different color than that of the original.
// If we insert the clone into the original document, the two styles with the same name will cause a clash.
SharedPtr<Document> srcDoc = dstDoc->Clone();
srcDoc->get_Styles()->idx_get(u"MyStyle")->get_Font()->set_Color(System::Drawing::Color::get_Red());
// When we enable SmartStyleBehavior and use the KeepSourceFormatting import format mode,
// Aspose.Words will resolve style clashes by converting source document styles.
// with the same names as destination styles into direct paragraph attributes.
auto options = MakeObject<ImportFormatOptions>();
options->set_SmartStyleBehavior(true);
builder->InsertDocument(srcDoc, ImportFormatMode::KeepSourceFormatting, options);
dstDoc->Save(ArtifactsDir + u"DocumentBuilder.SmartStyleBehavior.docx");

#include <Aspose.Words.Cpp/ImportFormatOptions.h>

+ Inheritance diagram for Aspose::Words::ImportFormatOptions:

Public Member Functions

 ImportFormatOptions ()
 
bool get_ForceCopyStyles () const
 Gets or sets a boolean value indicating either to copy conflicting styles in KeepSourceFormatting mode. The default value is false. More...
 
bool get_IgnoreHeaderFooter () const
 Gets or sets a boolean value that specifies that source formatting of headers/footers content ignored if KeepSourceFormatting mode is used. The default value is true. More...
 
bool get_IgnoreTextBoxes () const
 Gets or sets a boolean value that specifies that source formatting of textboxes content ignored if KeepSourceFormatting mode is used. The default value is true. More...
 
bool get_KeepSourceNumbering () const
 Gets or sets a boolean value that specifies how the numbering will be imported when it clashes in source and destination documents. The default value is false. More...
 
bool get_MergePastedLists () const
 Gets or sets a boolean value that specifies whether pasted lists will be merged with surrounding lists. The default value is false. More...
 
bool get_SmartStyleBehavior () const
 Gets or sets a boolean value that specifies how styles will be imported when they have equal names in source and destination documents. The default value is false. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_ForceCopyStyles (bool value)
 Setter for get_ForceCopyStyles. More...
 
void set_IgnoreHeaderFooter (bool value)
 Setter for get_IgnoreHeaderFooter. More...
 
void set_IgnoreTextBoxes (bool value)
 Setter for get_IgnoreTextBoxes. More...
 
void set_KeepSourceNumbering (bool value)
 Setter for get_KeepSourceNumbering. More...
 
void set_MergePastedLists (bool value)
 Setter for get_MergePastedLists. More...
 
void set_SmartStyleBehavior (bool value)
 Setter for get_SmartStyleBehavior. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Constructor & Destructor Documentation

◆ ImportFormatOptions()

Aspose::Words::ImportFormatOptions::ImportFormatOptions ( )

Member Function Documentation

◆ get_ForceCopyStyles()

bool Aspose::Words::ImportFormatOptions::get_ForceCopyStyles ( ) const

Gets or sets a boolean value indicating either to copy conflicting styles in KeepSourceFormatting mode. The default value is false.

By default, if a matching style already exists in a destination document, the source style formatting is expanded into direct node attributes and the style of this node is reset to a default.

When this option is set to true, the source style will be forcibly copied into destination document with unique name and applied to the imported node.

Note, in this case it is not guaranteed that formatting of the imported node in destination document will be preserved.

◆ get_IgnoreHeaderFooter()

bool Aspose::Words::ImportFormatOptions::get_IgnoreHeaderFooter ( ) const

Gets or sets a boolean value that specifies that source formatting of headers/footers content ignored if KeepSourceFormatting mode is used. The default value is true.

Examples

Shows how to specifies ignoring or not source formatting of headers/footers content.

auto dstDoc = MakeObject<Document>(MyDir + u"Document.docx");
auto srcDoc = MakeObject<Document>(MyDir + u"Header and footer types.docx");
auto importFormatOptions = MakeObject<ImportFormatOptions>();
importFormatOptions->set_IgnoreHeaderFooter(false);
dstDoc->AppendDocument(srcDoc, ImportFormatMode::KeepSourceFormatting, importFormatOptions);
dstDoc->Save(ArtifactsDir + u"DocumentBuilder.DoNotIgnoreHeaderFooter.docx");

◆ get_IgnoreTextBoxes()

bool Aspose::Words::ImportFormatOptions::get_IgnoreTextBoxes ( ) const

Gets or sets a boolean value that specifies that source formatting of textboxes content ignored if KeepSourceFormatting mode is used. The default value is true.

Examples

Shows how to manage text box formatting while appending a document.

// Create a document that will have nodes from another document inserted into it.
auto dstDoc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(dstDoc);
builder->Writeln(u"Hello world!");
// Create another document with a text box, which we will import into the first document.
auto srcDoc = MakeObject<Document>();
builder = MakeObject<DocumentBuilder>(srcDoc);
SharedPtr<Shape> textBox = builder->InsertShape(ShapeType::TextBox, 300, 100);
builder->MoveTo(textBox->get_FirstParagraph());
builder->get_ParagraphFormat()->get_Style()->get_Font()->set_Name(u"Courier New");
builder->get_ParagraphFormat()->get_Style()->get_Font()->set_Size(24);
builder->Write(u"Textbox contents");
// Set a flag to specify whether to clear or preserve text box formatting
// while importing them to other documents.
auto importFormatOptions = MakeObject<ImportFormatOptions>();
importFormatOptions->set_IgnoreTextBoxes(ignoreTextBoxes);
// Import the text box from the source document into the destination document,
// and then verify whether we have preserved the styling of its text contents.
auto importer = MakeObject<NodeImporter>(srcDoc, dstDoc, ImportFormatMode::KeepSourceFormatting, importFormatOptions);
auto importedTextBox = System::DynamicCast<Shape>(importer->ImportNode(textBox, true));
dstDoc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(1)->AppendChild(importedTextBox);
if (ignoreTextBoxes)
{
ASPOSE_ASSERT_EQ(12.0, importedTextBox->get_FirstParagraph()->get_Runs()->idx_get(0)->get_Font()->get_Size());
ASSERT_EQ(u"Times New Roman", importedTextBox->get_FirstParagraph()->get_Runs()->idx_get(0)->get_Font()->get_Name());
}
else
{
ASPOSE_ASSERT_EQ(24.0, importedTextBox->get_FirstParagraph()->get_Runs()->idx_get(0)->get_Font()->get_Size());
ASSERT_EQ(u"Courier New", importedTextBox->get_FirstParagraph()->get_Runs()->idx_get(0)->get_Font()->get_Name());
}
dstDoc->Save(ArtifactsDir + u"DocumentBuilder.IgnoreTextBoxes.docx");

◆ get_KeepSourceNumbering()

bool Aspose::Words::ImportFormatOptions::get_KeepSourceNumbering ( ) const

Gets or sets a boolean value that specifies how the numbering will be imported when it clashes in source and destination documents. The default value is false.

Examples

Shows how to import a document with numbered lists.

auto srcDoc = MakeObject<Document>(MyDir + u"List source.docx");
auto dstDoc = MakeObject<Document>(MyDir + u"List destination.docx");
ASSERT_EQ(4, dstDoc->get_Lists()->get_Count());
auto options = MakeObject<ImportFormatOptions>();
// If there is a clash of list styles, apply the list format of the source document.
// Set the "KeepSourceNumbering" property to "false" to not import any list numbers into the destination document.
// Set the "KeepSourceNumbering" property to "true" import all clashing
// list style numbering with the same appearance that it had in the source document.
options->set_KeepSourceNumbering(isKeepSourceNumbering);
dstDoc->AppendDocument(srcDoc, ImportFormatMode::KeepSourceFormatting, options);
dstDoc->UpdateListLabels();
ASSERT_EQ(isKeepSourceNumbering ? 5 : 4, dstDoc->get_Lists()->get_Count());

Shows how resolve a clash when importing documents that have lists with the same list definition identifier.

auto srcDoc = MakeObject<Document>(MyDir + u"List with the same definition identifier - source.docx");
auto dstDoc = MakeObject<Document>(MyDir + u"List with the same definition identifier - destination.docx");
// Set the "KeepSourceNumbering" property to "true" to apply a different list definition ID
// to identical styles as Aspose.Words imports them into destination documents.
auto importFormatOptions = MakeObject<ImportFormatOptions>();
importFormatOptions->set_KeepSourceNumbering(true);
dstDoc->AppendDocument(srcDoc, ImportFormatMode::UseDestinationStyles, importFormatOptions);
dstDoc->UpdateListLabels();

Shows how to resolve list numbering clashes in source and destination documents.

// Open a document with a custom list numbering scheme, and then clone it.
// Since both have the same numbering format, the formats will clash if we import one document into the other.
auto srcDoc = MakeObject<Document>(MyDir + u"Custom list numbering.docx");
SharedPtr<Document> dstDoc = srcDoc->Clone();
// When we import the document's clone into the original and then append it,
// then the two lists with the same list format will join.
// If we set the "KeepSourceNumbering" flag to "false", then the list from the document clone
// that we append to the original will carry on the numbering of the list we append it to.
// This will effectively merge the two lists into one.
// If we set the "KeepSourceNumbering" flag to "true", then the document clone
// list will preserve its original numbering, making the two lists appear as separate lists.
auto importFormatOptions = MakeObject<ImportFormatOptions>();
importFormatOptions->set_KeepSourceNumbering(keepSourceNumbering);
auto importer = MakeObject<NodeImporter>(srcDoc, dstDoc, ImportFormatMode::KeepDifferentStyles, importFormatOptions);
for (const auto& paragraph : System::IterateOver<Paragraph>(srcDoc->get_FirstSection()->get_Body()->get_Paragraphs()))
{
SharedPtr<Node> importedNode = importer->ImportNode(paragraph, true);
dstDoc->get_FirstSection()->get_Body()->AppendChild(importedNode);
}
dstDoc->UpdateListLabels();
if (keepSourceNumbering)
{
ASSERT_EQ(String(u"6. Item 1\r\n") + u"7. Item 2 \r\n" + u"8. Item 3\r\n" + u"9. Item 4\r\n" + u"6. Item 1\r\n" + u"7. Item 2 \r\n" +
u"8. Item 3\r\n" + u"9. Item 4",
dstDoc->get_FirstSection()->get_Body()->ToString(SaveFormat::Text).Trim());
}
else
{
ASSERT_EQ(String(u"6. Item 1\r\n") + u"7. Item 2 \r\n" + u"8. Item 3\r\n" + u"9. Item 4\r\n" + u"10. Item 1\r\n" + u"11. Item 2 \r\n" +
u"12. Item 3\r\n" + u"13. Item 4",
dstDoc->get_FirstSection()->get_Body()->ToString(SaveFormat::Text).Trim());
}

◆ get_MergePastedLists()

bool Aspose::Words::ImportFormatOptions::get_MergePastedLists ( ) const

Gets or sets a boolean value that specifies whether pasted lists will be merged with surrounding lists. The default value is false.

Examples

Shows how to merge lists from a documents.

auto srcDoc = MakeObject<Document>(MyDir + u"List item.docx");
auto dstDoc = MakeObject<Document>(MyDir + u"List destination.docx");
auto options = MakeObject<ImportFormatOptions>();
options->set_MergePastedLists(true);
// Set the "MergePastedLists" property to "true" pasted lists will be merged with surrounding lists.
dstDoc->AppendDocument(srcDoc, ImportFormatMode::UseDestinationStyles, options);
dstDoc->Save(ArtifactsDir + u"Document.MergePastedLists.docx");

◆ get_SmartStyleBehavior()

bool Aspose::Words::ImportFormatOptions::get_SmartStyleBehavior ( ) const

Gets or sets a boolean value that specifies how styles will be imported when they have equal names in source and destination documents. The default value is false.

When this option is enabled, the source style will be expanded into a direct attributes inside a destination document, if KeepSourceFormatting importing mode is used.

When this option is disabled, the source style will be expanded only if it is numbered. Existing destination attributes will not be overridden, including lists.

Examples

Shows how to resolve duplicate styles while inserting documents.

auto dstDoc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(dstDoc);
SharedPtr<Style> myStyle = builder->get_Document()->get_Styles()->Add(StyleType::Paragraph, u"MyStyle");
myStyle->get_Font()->set_Size(14);
myStyle->get_Font()->set_Name(u"Courier New");
myStyle->get_Font()->set_Color(System::Drawing::Color::get_Blue());
builder->get_ParagraphFormat()->set_StyleName(myStyle->get_Name());
builder->Writeln(u"Hello world!");
// Clone the document and edit the clone's "MyStyle" style, so it is a different color than that of the original.
// If we insert the clone into the original document, the two styles with the same name will cause a clash.
SharedPtr<Document> srcDoc = dstDoc->Clone();
srcDoc->get_Styles()->idx_get(u"MyStyle")->get_Font()->set_Color(System::Drawing::Color::get_Red());
// When we enable SmartStyleBehavior and use the KeepSourceFormatting import format mode,
// Aspose.Words will resolve style clashes by converting source document styles.
// with the same names as destination styles into direct paragraph attributes.
auto options = MakeObject<ImportFormatOptions>();
options->set_SmartStyleBehavior(true);
builder->InsertDocument(srcDoc, ImportFormatMode::KeepSourceFormatting, options);
dstDoc->Save(ArtifactsDir + u"DocumentBuilder.SmartStyleBehavior.docx");

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::ImportFormatOptions::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

virtual bool Aspose::Words::ImportFormatOptions::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ set_ForceCopyStyles()

void Aspose::Words::ImportFormatOptions::set_ForceCopyStyles ( bool  value)

◆ set_IgnoreHeaderFooter()

void Aspose::Words::ImportFormatOptions::set_IgnoreHeaderFooter ( bool  value)

◆ set_IgnoreTextBoxes()

void Aspose::Words::ImportFormatOptions::set_IgnoreTextBoxes ( bool  value)

◆ set_KeepSourceNumbering()

void Aspose::Words::ImportFormatOptions::set_KeepSourceNumbering ( bool  value)

◆ set_MergePastedLists()

void Aspose::Words::ImportFormatOptions::set_MergePastedLists ( bool  value)

◆ set_SmartStyleBehavior()

void Aspose::Words::ImportFormatOptions::set_SmartStyleBehavior ( bool  value)

◆ Type()

static const System::TypeInfo& Aspose::Words::ImportFormatOptions::Type ( )
static