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.
Thu Apr 21, 2016 2:32 am
Now I have a docx file and there are some paragraph in the file, I want to insert a table after the third paragraph .How can I realize this ? there may be a fourth paragraph after the third paragraph ,it means the docx file contains more than 3 paragraphs.
thanks.
-
iceblueDDX123
-
- Posts: 34
- Joined: Tue Apr 19, 2016 9:43 am
Thu Apr 21, 2016 6:36 am
Hi,
Thanks for your posting.
Please refer to the following solution.
- Code: Select all
Document doc = new Document();
doc.LoadFromFile("..\\..\\Test1.docx");
//Get the first second
Section section = doc.Sections[0];
//Get the third paragraph in the first second
Paragraph paragraph = section.Paragraphs[2];
//Get the index of paragraph in its section
int index = section.Body.ChildObjects.IndexOf(paragraph);
//Create a new table
Table table = new Table(doc, true);
table.ResetCells(2, 2);
//Insert the table after the third paragraph
section.Body.ChildObjects.Insert(index + 1, table.Clone());
doc.SaveToFile("sample.docx", FileFormat.Docx2010);
Best Regards,
Amy
E-iceblue support team
-
amy.zhao
-
- Posts: 2766
- Joined: Wed Jun 27, 2012 8:50 am
Tue Apr 26, 2016 8:41 am
Hi,
Has your issue been resolved?
Thanks for your feedback in advance.
Best Regards,
Amy
E-iceblue support team
-
amy.zhao
-
- Posts: 2766
- Joined: Wed Jun 27, 2012 8:50 am
Wed May 04, 2016 6:44 am
amy.zhao wrote:Hi,
Has your issue been resolved?
Thanks for your feedback in advance.
Best Regards,
Amy
E-iceblue support team
Yes , my issue has been resolved.thank you !
-
iceblueDDX123
-
- Posts: 34
- Joined: Tue Apr 19, 2016 9:43 am
Wed May 04, 2016 7:29 am
Hello,
Thanks for your feedback. Please contact us if you have any questions.
Sincerely,
Gary
E-iceblue support team
-
Gary.zhang
-
- Posts: 1380
- Joined: Thu Apr 04, 2013 1:30 am