java.lang.Objectcom.aspose.words.ImportFormatOptions
public class ImportFormatOptions
Example:
Document destDoc = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.DestinationDocument.docx");
Document sourceDoc1 = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.SourceDocument01.docx");
Document sourceDoc2 = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.SourceDocument02.docx");
DocumentBuilder builder = new DocumentBuilder(destDoc);
builder.moveToDocumentEnd();
builder.insertBreak(BreakType.PAGE_BREAK);
builder.moveToDocumentEnd();
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.setSmartStyleBehavior(true);
// When SmartStyleBehavior is enabled,
// a source style will be expanded into a direct attributes inside a destination document,
// if KeepSourceFormatting importing mode is used.
builder.insertDocument(sourceDoc1, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions);
builder.moveToDocumentEnd();
builder.insertBreak(BreakType.PAGE_BREAK);
// When SmartStyleBehavior is disabled,
// a source style will be expanded only if it is numbered.
// Existing destination attributes will not be overridden, including lists.
builder.insertDocument(sourceDoc2, ImportFormatMode.USE_DESTINATION_STYLES);
destDoc.save(getArtifactsDir() + "DocumentBuilder.SmartStyleBehavior.ResultDocument.docx");
Constructor Summary |
---|
ImportFormatOptions()
|
Property Getters/Setters Summary | ||
---|---|---|
boolean | getIgnoreTextBoxes() | |
void | setIgnoreTextBoxes(boolean value) | |
Gets or sets a boolean value that indicates whether to ignore formatting in the text boxes of
the source destination during the import.
Default value is true .
|
||
boolean | getKeepSourceNumbering() | |
void | setKeepSourceNumbering(boolean value) | |
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 .
|
||
boolean | getSmartStyleBehavior() | |
void | setSmartStyleBehavior(boolean value) | |
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 .
|
Constructor Detail |
---|
public ImportFormatOptions()
Property Getters/Setters Detail |
---|
getIgnoreTextBoxes/setIgnoreTextBoxes | |
public boolean getIgnoreTextBoxes() / public void setIgnoreTextBoxes(boolean value) |
true
.
Example:
Shows how to manage formatting in the text boxes of the source destination during the import.Document dstDoc = new Document(getMyDir() + "DocumentBuilder.IgnoreTextBoxes.DestinationDocument.docx"); Document srcDoc = new Document(getMyDir() + "DocumentBuilder.IgnoreTextBoxes.SourceDocument.docx"); ImportFormatOptions importFormatOptions = new ImportFormatOptions(); // Keep the source text boxes formatting when importing importFormatOptions.setIgnoreTextBoxes(false); NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions); ParagraphCollection paragraphs = srcDoc.getFirstSection().getBody().getParagraphs(); for (int i = 0; i < paragraphs.getCount(); i++) { Paragraph srcPara = paragraphs.get(i); Node importedNode = importer.importNode(srcPara, true); dstDoc.getFirstSection().getBody().appendChild(importedNode); } dstDoc.save(getArtifactsDir() + "DocumentBuilder.IgnoreTextBoxes.ResultDocument.docx");
getKeepSourceNumbering/setKeepSourceNumbering | |
public boolean getKeepSourceNumbering() / public void setKeepSourceNumbering(boolean value) |
false
.
Example:
Shows how the numbering will be imported when it clashes in source and destination documents.Document dstDoc = new Document(getMyDir() + "DocumentBuilder.KeepSourceNumbering.DestinationDocument.docx"); Document srcDoc = new Document(getMyDir() + "DocumentBuilder.KeepSourceNumbering.SourceDocument.docx"); ImportFormatOptions importFormatOptions = new ImportFormatOptions(); // Keep source list formatting when importing numbered paragraphs importFormatOptions.setKeepSourceNumbering(true); NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions); ParagraphCollection paragraphs = srcDoc.getFirstSection().getBody().getParagraphs(); for (int i = 0; i < paragraphs.getCount(); i++) { Paragraph srcPara = paragraphs.get(i); Node importedNode = importer.importNode(srcPara, true); dstDoc.getFirstSection().getBody().appendChild(importedNode); } dstDoc.save(getArtifactsDir() + "DocumentBuilder.KeepSourceNumbering.ResultDocument.docx");
getSmartStyleBehavior/setSmartStyleBehavior | |
public boolean getSmartStyleBehavior() / public void setSmartStyleBehavior(boolean value) |
false
.
When this option is enabled, the source style will be expanded into a direct attributes inside a
destination document, if
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.
Example:
Shows how to resolve styles behavior while inserting documents.Document destDoc = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.DestinationDocument.docx"); Document sourceDoc1 = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.SourceDocument01.docx"); Document sourceDoc2 = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.SourceDocument02.docx"); DocumentBuilder builder = new DocumentBuilder(destDoc); builder.moveToDocumentEnd(); builder.insertBreak(BreakType.PAGE_BREAK); builder.moveToDocumentEnd(); ImportFormatOptions importFormatOptions = new ImportFormatOptions(); importFormatOptions.setSmartStyleBehavior(true); // When SmartStyleBehavior is enabled, // a source style will be expanded into a direct attributes inside a destination document, // if KeepSourceFormatting importing mode is used. builder.insertDocument(sourceDoc1, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions); builder.moveToDocumentEnd(); builder.insertBreak(BreakType.PAGE_BREAK); // When SmartStyleBehavior is disabled, // a source style will be expanded only if it is numbered. // Existing destination attributes will not be overridden, including lists. builder.insertDocument(sourceDoc2, ImportFormatMode.USE_DESTINATION_STYLES); destDoc.save(getArtifactsDir() + "DocumentBuilder.SmartStyleBehavior.ResultDocument.docx");