We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ImportFormatMode Styles Not working as expected

Hi There,

We are facing problems using the Aspose.Words library in our solution. The issue is as follows.

The problem line of code is the call on an Aspose.Words.NodeImporter instance whose ImportFormatMode (the third argument) we have set to ImportFormatMode.UseDestinationStyles, as this should in theory create the behaviour you require. The other option for this argument is ImportFormatMode.KeepSourceFormatting, which is what our deployed code currently is.

Here is the calling method in its entirety.

#region Insert document (pattern from the Aspose SDK)

///

/// Inserts content of the external document after the specified node.

/// Section breaks and section formatting of the inserted document are ignored.

/// The insertion is going on the story child level, so the specified node should

/// be either a paragraph or table.

///

/// Node in the destination document after which the content

/// should be inserted.

/// This node should be a story child level node (paragraph or table).

/// Document to insert.

public void InsertDocument(Node insertAfterNode, Document srcDoc)

{

// We need to make sure that the specified node is either pargraph or table.

if (!((insertAfterNode.NodeType == NodeType.Paragraph) ||

(insertAfterNode.NodeType == NodeType.Table)))

throw new ArgumentException("The destination node should be either paragraph or table.");

// We will be inserting into the parent of the destination paragraph.

CompositeNode dstStory = insertAfterNode.ParentNode;

// This object will be translating styles and lists during the import.

NodeImporter importer = new NodeImporter(srcDoc, insertAfterNode.Document,

ImportFormatMode.UseDestinationStyles);

// Loop through all sections in the source document.

foreach (Section srcSection in srcDoc.Sections)

{

// Loop through all block level nodes (paragraphs and tables) in the body of the section.

foreach (Node srcNode in srcSection.Body)

{

// Do not insert node if it is a last empty paragarph in the section.

Paragraph para = srcNode as Paragraph;

if ((para != null) && para.IsEndOfSection && !para.HasChildNodes)

break;

// This creates a clone of the node, suitable for insertion into the destination document.

Node newNode = importer.ImportNode(srcNode, true);

// Insert new node after the reference node.

dstStory.InsertAfter(newNode, insertAfterNode);

insertAfterNode = newNode;

}

}

}

#endregion

However we have found that ImportFormatMode.UseDestinationStyles does not behave as expected. What it does is produce new styles in the destination document with names like "Heading 1 Char", whereas it should really just be "Heading 1". Also attempting to manipulate the "Heading 1 Char" style fails and causes Word 2003 (but not Word 2007) to crash.

Please let us know if there is any further information that you would like us to provide.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I can’t reproduce this issue on my side. I use the latest version of Aspose.Words 5.2.2.

Could you please attach your documents for testing? I will try to reproduce the problem and provide you more information.

Best regards.

Hi,

I have attached the sample documents that the developers have pointed out are falling over. Further more we have version 5.1.0 installed and it would not be a very likeable path for us to change the library in our production environment for technical reasons.

Regards

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I managed to reproduce the problem in my side and created new issue #5879 in our defect database. I will notify you as soon as it is fixed.

Best regards.

Hi

Can you please let me know where the issue is? How long will it take to fix and when can we have the updated files.

Regards

Muhammad.

Hi

Thanks for your inquiry. Currently I can’t provide you any estimate. We will investigate the issue and provide you more information.

Best regards.

Hi there, Any idea on when we can have an update on this issue.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Please expect a reply before next hotfix (within 2-3 weeks).

Best regards.

Hi There,

Any update on this issue would be appreciated.

Thanks

Muhammad.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. This issue is already fixed in our current code base. Release will be published soon. I will notify you.

Best regards.

The issues you have found earlier (filed as 5879) have been fixed in this update.