java.lang.Objectcom.aspose.words.ImportFormatOptions
public class ImportFormatOptions
Example:
Document dstDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(dstDoc);
Style myStyle = builder.getDocument().getStyles().add(StyleType.PARAGRAPH, "MyStyle");
myStyle.getFont().setSize(14.0);
myStyle.getFont().setName("Courier New");
myStyle.getFont().setColor(Color.BLUE);
// Append text with custom style
builder.getParagraphFormat().setStyleName(myStyle.getName());
builder.writeln("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 append this document to the original, the different styles will clash since they are the same name, and we will need to resolve it
Document srcDoc = dstDoc.deepClone();
srcDoc.getStyles().get("MyStyle").getFont().setColor(Color.RED);
// When SmartStyleBehavior is enabled,
// a source style will be expanded into a direct attributes inside a destination document,
// if KeepSourceFormatting importing mode is used
ImportFormatOptions options = new ImportFormatOptions();
options.setSmartStyleBehavior(true);
builder.insertDocument(srcDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING, options);
dstDoc.save(getArtifactsDir() + "DocumentBuilder.SmartStyleBehavior.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.// Create a document and add text Document dstDoc = new Document(); DocumentBuilder builder = new DocumentBuilder(dstDoc); builder.writeln("Hello world! Text box to follow."); // Create another document with a textbox, and insert some formatted text into it Document srcDoc = new Document(); builder = new DocumentBuilder(srcDoc); Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 300.0, 100.0); builder.moveTo(textBox.getFirstParagraph()); builder.getParagraphFormat().getStyle().getFont().setName("Courier New"); builder.getParagraphFormat().getStyle().getFont().setSize(24.0d); builder.write("Textbox contents"); // When we import the document with the textbox as a node into the first document, by default the text inside the text box will keep its formatting // Setting the IgnoreTextBoxes flag will clear the formatting during importing of the node ImportFormatOptions importFormatOptions = new ImportFormatOptions(); importFormatOptions.setIgnoreTextBoxes(true); NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions); ParagraphCollection srcParas = srcDoc.getFirstSection().getBody().getParagraphs(); for (int i = 0; i < srcParas.getCount(); i++) { Paragraph srcPara = srcParas.get(i); Node importedNode = importer.importNode(srcPara, true); dstDoc.getFirstSection().getBody().appendChild(importedNode); } dstDoc.save(getArtifactsDir() + "DocumentBuilder.IgnoreTextBoxes.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.// Open a document with a custom list numbering scheme and clone it // Since both have the same numbering format, the formats will clash if we import one document into the other Document srcDoc = new Document(getMyDir() + "Custom list numbering.docx"); Document dstDoc = srcDoc.deepClone(); ImportFormatOptions importFormatOptions = new ImportFormatOptions(); // Both documents have the same numbering in their lists, but if we set this flag to false and then import one document into the other // the numbering of the imported source document will continue from where it ends in the destination document importFormatOptions.setKeepSourceNumbering(false); NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions); ParagraphCollection srcParas = srcDoc.getFirstSection().getBody().getParagraphs(); for (int i = 0; i < srcParas.getCount(); i++) { Paragraph srcPara = srcParas.get(i); Node importedNode = importer.importNode(srcPara, true); dstDoc.getFirstSection().getBody().appendChild(importedNode); } dstDoc.save(getArtifactsDir() + "DocumentBuilder.KeepSourceNumbering.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 dstDoc = new Document(); DocumentBuilder builder = new DocumentBuilder(dstDoc); Style myStyle = builder.getDocument().getStyles().add(StyleType.PARAGRAPH, "MyStyle"); myStyle.getFont().setSize(14.0); myStyle.getFont().setName("Courier New"); myStyle.getFont().setColor(Color.BLUE); // Append text with custom style builder.getParagraphFormat().setStyleName(myStyle.getName()); builder.writeln("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 append this document to the original, the different styles will clash since they are the same name, and we will need to resolve it Document srcDoc = dstDoc.deepClone(); srcDoc.getStyles().get("MyStyle").getFont().setColor(Color.RED); // When SmartStyleBehavior is enabled, // a source style will be expanded into a direct attributes inside a destination document, // if KeepSourceFormatting importing mode is used ImportFormatOptions options = new ImportFormatOptions(); options.setSmartStyleBehavior(true); builder.insertDocument(srcDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING, options); dstDoc.save(getArtifactsDir() + "DocumentBuilder.SmartStyleBehavior.docx");