In the original document, I have 2 list notes elements. But they are not belong to the same list. So the first list note has the number 1 and the second list note has also number 1.
When we add these dotes elements to a new document using ImportNode with ImportFormatMode.UseDestinationStyles, the second list note get incremented. (I notice that when we use ImportFormatMode.KeepSourceFormatting the number get not incremented).
I have attached a sample application demonstrating the issue.
Can you propose a solution for this issue or a workaround?
Thanks for your inquiry. I suspect you’re using an older version of Aspose.Words i.e. 11.8.0; I would suggest you please upgrade to the latest version of Aspose.Words (v 11.9.0) from the following link. I hope, this helps. https://releases.aspose.com/words/net
Moreover, please try running the following code on your side and let us know how it goes.
Document srcDoc = new Document(@"C:\Temp\docNotes.docm");
Document dstDoc = new Document();
dstDoc.RemoveAllChildren();
dstDoc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);
dstDoc.Save(@"C:\Temp\out.docm");
Thanks for your response. The issue still exist in Aspose.Words 11.9.0. Unfortunately in our case we can’t use AppendDocument. We have absolutely use ImportNode.
Thanks for your response. In your code, you are using ImportNode of Document object (which we cannot use). However, we are using ImportNode of NodeImporter. Afterward, we use DocumentBuilder to create our doucment.
So is it possible to provide an aspose.word fix that will make my previously attached application work?
Unfortunately, we have reopen this case and the above fix didn’t work for us. Please for got about my previous posting and focus the the new sample application attached here.
Here is again our scenario:
I have create a sample app representing the way how we generate reports:
We create a Word.Document
Add part1 content to it with a list starting from 1
Add part2 content to it with a list starting from 1
Save the document.
The problem: The list in part2 is linked to the list in part1 even they are 2 separate lists. Part 2 list start from 2 instead of 1 in the output.
We want to keep the list independent from each other (both list should start from 1).
Note : this issue is not occurring when we use UseDestinationStyles. but We must use UseDestinationStyles.
Is there a way the keep the two list independent while using UseDestinationStyles? (any code we can introduce between insert part1 and insert part2 for example)
Well, in case you choose ImportFormatMode.UseDestinationStyles option, you can ensure that lists in both source and destination documents has different styles. For example, you can clone/copy the list style ‘Note Titre 1’ in ‘part2.docm’ to a temp style named ‘Note Titre 1_0’ and apply this new style to the list. This makes the names of the styles different and satisfies your requirement.
// Insert Part 2
wordDocBuilder.MoveToDocumentEnd();
var sourceDocument2 = new Document(part2);
foreach (Paragraph para in sourceDocument2.GetChildNodes(NodeType.Paragraph, true))
{
if (para.IsListItem)
{
Style newStyle = sourceDocument2.Styles.AddCopy(para.ParagraphFormat.Style);
para.ParagraphFormat.Style = newStyle;
}
}
InsertDocument(afterNode, sourceDocument2);