When copying a section the style is not preserved


#1

Hello,
When running the following code, the style of the second document is not preserved. The bullets are transformed into numbers.
protected void Page_Load(object sender, EventArgs e)
{
var doc1 = new Document(@“C:\1.docx”);
var doc2 = new Document(@“c:\2.docx”);

       var sectionCount = doc2.Sections.Count;

       var nodeImporter = new NodeImporter(doc2, doc1, ImportFormatMode.KeepSourceFormatting);
        for (int i = 0; i < sectionCount; i++)
        {
            var section = doc2.Sections[i];
            var importedSection = (Section) nodeImporter.ImportNode(section, true);
            importedSection.PageSetup.MultiplePages = section.PageSetup.MultiplePages;

            CopySection(importedSection, doc1);
        }

        doc1.Save(@"c:\issue.docx");

}
public void CopySection(Section importedSection, Document mainDocument)
{
var mainDocumentLastSection = mainDocument.LastSection;
var importedSectionNodes = importedSection.Body.ChildNodes.ToArray();
foreach (var childNode in importedSectionNodes)
mainDocumentLastSection.Body.ChildNodes.Add(childNode);
}
I’ve also attached the documents.
Thank youdocuments.zip (60.4 KB)


#2

@adrian.anton

You are facing the expected behavior of Aspose.Words. Please note that Aspose.Words mimics the behavior of Aspose.Words. If you copy the content of source document into destination document using MS Word, you will get the same output.


#3

The thing is that even when I’m creating a new document and adding the provided documents by copying them into the newly created one, this is still happening. And also, the styles are totally different and have different names.
I was able to reproduce this by using the following code:
protected void Page_Load(object sender, EventArgs e)
{
var doc1 = new Document(@“C:\1.docx”);
var doc2 = new Document(@“c:\2.docx”);
var mainDoc = new Document();
mainDoc.Cleanup();

var sectionCount = doc1.Sections.Count;
       
var nodeImporter = new NodeImporter(doc1, mainDoc, ImportFormatMode.KeepSourceFormatting);
for (int i = 0; i < sectionCount; i++)
{
	var section = doc1.Sections[i];
    var importedSection = (Section) nodeImporter.ImportNode(section, true);
    importedSection.PageSetup.MultiplePages = section.PageSetup.MultiplePages;

	CopySection(importedSection, mainDoc);
}

sectionCount = doc2.Sections.Count;
nodeImporter = new NodeImporter(doc2, mainDoc, ImportFormatMode.KeepSourceFormatting);
for (int i = 0; i < sectionCount; i++)
{
	var section = doc2.Sections[i];
    var importedSection = (Section) nodeImporter.ImportNode(section, true);
    importedSection.PageSetup.MultiplePages = section.PageSetup.MultiplePages;

	CopySection(importedSection, mainDoc);
}

mainDoc.Save(@"c:\issue.docx");

}

public void CopySection(Section importedSection, Document mainDocument)
{
var mainDocumentLastSection = mainDocument.LastSection;
var importedSectionNodes = importedSection.Body.ChildNodes.ToArray();
foreach (var childNode in importedSectionNodes)
mainDocumentLastSection.Body.ChildNodes.Add(childNode);
}
I’ve attached the newly resulted document.
issue.zip (14.0 KB)


#4

@adrian.anton

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-18873. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.