Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Nov 16, 2011 7:06 pm

Good afternoon! My name is Antonio and I'm from Brazil.
I wonder how do I copy the entire contents of the loaded document, create another page and paste the copied content.
It looked here on the site but could not find the solution.
Thank you!

Pastor
 
Posts: 1
Joined: Thu Oct 27, 2011 7:38 pm

Sat Nov 19, 2011 10:25 am

Hello Pastor,

Sorry for late reply and thank you for your patience.

There is no function to copy the entire contents to another new page. You need to copy the content one by one according to different type.
The following code display how to copy plain text to another page.
Code: Select all
using Spire.Doc;
using Spire.Doc.Documents;

namespace _205CopyAndPaste
{
    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document(@"..\..\sample.docx", FileFormat.Docx2010);

            CopyDocument(document);

            document.SaveToFile(@"..\..\result.docx", FileFormat.Docx2010);
            System.Diagnostics.Process.Start(@"..\..\result.docx");
        }

        static private void CopyDocument(Document document)
        {
            int secCount=document.Sections.Count;
            for(int i=0;i<secCount;i++)
            {
                Section destSection=document.AddSection();
                Section srcSection=document.Sections[i];

                for(int j=0;j<srcSection.Paragraphs.Count;j++)
                {
                    Paragraph srcParagraph=srcSection.Paragraphs[j];
                    Paragraph destParagraph=destSection.AddParagraph();
                    destParagraph.AppendText(srcParagraph.Text);
                }
           
            }

        }
    }
}


Please simulate the code to have a try.

Have a nice day.
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar

Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Return to Spire.Doc