Hi,
I’m seeing odd issue when importing node from one document to another one. The issue occurs we have style with the same name in both files, but in imported one we have spacing values set and in the other one we have them set on auto. In that situation when we have set a custom spacing value for a node when importing it using ImportNode method, the node that is the result of that method has the spacing value set to auto rather than using our custom value of spacing.
Could you please take a look and let us know if this can be fixed somehow?
Thanks,
Patryk
AsposeSpacingIssue.zip (21.6 KB)
@acturisaspose Document.ImportNode(Node, bool) overload uses the ImportFormatMode.UseDestinationStyles
option to resolve formatting. In case of using ImportFormatMode.UseDestinationStyles
Aspose.Words uses the style defined in the destination document.
In your case if you need to preserve source formatting, you should either use ImportFormatMode.KeepDifferentStyles
or ImportFormatMode.KeepSourceFormatting
:
nodes.Add(doc2.ImportNode(childNode, true, ImportFormatMode.KeepSourceFormatting));
Shouldn’t the spacing work like other values, so when we have it set manually for specific node it should use that value rather than style value. It looks like the import of manually set spacing works properly in all other cases except one that I provided.
@acturisaspose Looks like this is another “interesting” MS Word behavior. If you unzip the output document and check the XML, you will see:
<w:p w:rsidR="00E62ED5" w:rsidP="00A270FF">
<w:pPr>
<w:pStyle w:val="Style1" />
<w:spacing w:before="840" w:after="840" />
<w:rPr>
<w:lang w:val="pl-PL" />
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="pl-PL" />
</w:rPr>
<w:t>Test string for</w:t>
</w:r>
</w:p>
As you can see spacing is still explicitly set <w:spacing w:before="840" w:after="840" />
, but MS Word uses spacing specified in the style. So Aspose.Words behaves correctly and imports explicitly set options of the paragraph properly, but MS Word ignores them.