Free Support Forum - aspose.com

List numbering get incremented where it shouldn't

Hi,

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?

thank you,

Hi Jawad,


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.
http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/default.aspx

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");


Best Regards,

Hi,

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.


Regards,

Hi Jawad,


Thanks for your inquiry. I believe, the following code will help you in achieving what you’re looking for:

public static void DoTest(string
source, string result)

{

var doc = new Document();

doc.FirstSection.Body.FirstParagraph.Remove();

try

{

var bodyDoc = new Document(source);

foreach (Paragraph srcPara in bodyDoc.FirstSection.Body.GetChildNodes(NodeType.Paragraph, true))

{

Node dstPara = doc.ImportNode(srcPara, true, ImportFormatMode.UseDestinationStyles);

doc.FirstSection.Body.AppendChild(dstPara);

}

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

doc.Save(result);

}


Please let me know if I can be of any further assistance.

Best regards,

Hi,

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?

Thank you,

Hi Jawad,


Thanks for your request. I am checking with this scenario and will get back to you soon.

Best regards,

Hi Jawad,


Thanks for your patience. You can achieve the same by using the following code snippet:

Document
dstDoc = new Document();

Document srcDoc = new Document(@"C:\Temp\docNotes.docm");

Node refPara = dstDoc.FirstSection.Body.LastParagraph;

NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.UseDestinationStyles);

foreach (Paragraph srcPara in srcDoc.FirstSection.Body.GetChildNodes(NodeType.Paragraph, true))

{

Node dstNode = importer.ImportNode(srcPara, true);

CompositeNode parentNode = refPara.ParentNode;

parentNode.InsertAfter(dstNode, refPara);

}

dstDoc.Save(@"C:\Temp\docNotesout.docm");


I hope, this helps.

Best regards,

Hi,

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:
1. We create a Word.Document
2. Add part1 content to it with a list starting from 1
3. Add part2 content to it with a list starting from 1
4. 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.

Thank you to investigate again this case.

Hi Jawad,


Thanks for your inquiry. This is the expected behaviour; I would suggest you please read the following article for more details:
http://www.aspose.com/docs/display/wordsnet/Controlling+How+Lists+are+Handled

If we can help you with anything else, please feel free to ask.

Best regards,

Thank you for your response.

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)

Thank you,

Hi Jawad,


Thanks for your inquiry.

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);


I hope, this helps.

Best regards,