Free Support Forum - aspose.com

Copy multiple column document to another document

Hi,

I'm trying to copy a multiple column document into another document, but end up with a document with only one column. I must be doing something seriously wrong here.

Here's the code:

while (oldDoc.Sections.Count > 0)

{

Section section = oldDoc.Sections[0];

Section newSection = (Section)_document.ImportNode(section, true);

oldDoc.Sections.RemoveAt(0);

_document.Sections.Add(newSection);

_document.Sections[_document.Sections.Count - 1].PageSetup.TextColumns.SetCount(2);

_document.Sections[_document.Sections.Count - 1].PageSetup.TextColumns.EvenlySpaced = true;

}

Hi

Thanks for your inquiry. I tried to use the following code for testing and all works fine on my side.

//Open destination document

Document dstDoc = new Document(@"Test009\in1.doc");

//Open source document

Document srcDoc = new Document(@"Test009\in2.doc");

foreach (Section srcSection in srcDoc.Sections)

{

//Import section

Section newSection = (Section)dstDoc.ImportNode(srcSection, true);

//Insert section

dstDoc.Sections.Add(newSection);

}

//Save output document

dstDoc.Save(@"Test009\out.doc");

Please attach your documents for testing.

Best regards.

Thanks!

Your loop worked.

Maybe it's got something to do with me removing the sections from the old doc in my while loop.