Insert section in the middle of the document

Technical support for Spire.Doc

Moderator: iceblue support

Insert section in the middle of the document

Postby emailregistrazioni » Wed Sep 12, 2012 12:19 pm

Hi,
I would like to add a section at any point in the document, not just at the end.

For Example: I have a document with 9 sections. I want it so open to make changes dynamically from code. I position it in the exact recovering the desired section with

Code: Select all
 Section section = document.Sections [2];


At this point I would like to insert a new section between the section number 2 and number 3 (since then a total of 10 sections), but if I try to do so

Code: Select all
Section section = document.AddSection ();


rightly I add the section at the bottom of the document.

What is the correct way to do what I want?
emailregistrazioni
 
Posts: 11
Joined: Sun Sep 18, 2011 9:32 pm

Re: Insert section in the middle of the document

Postby amy.zhao » Thu Sep 13, 2012 9:03 am

Dear emailregistrazioni,

Thanks for your inquiry.

About your problem, we provide a sample demo. Hope it can help you.
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile(@"sample.docx", FileFormat.Docx);

            Section sec = new Section(doc);
            sec.AddParagraph().AppendText("This is a section inserted");

            doc.Sections.Insert(2, sec);

            doc.SaveToFile(@"result.docx", FileFormat.Docx);

If you have any problems, please feel free to contact us.

Best wishes,
Amy
e-iceblue support
User avatar
amy.zhao
 
Posts: 2251
Joined: Wed Jun 27, 2012 8:50 am


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests

cron