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 Mar 21, 2018 5:40 pm

Hey, So I've been trying to Delete some part in my word document but only text were deleted and image didnt
Here is my code:

Document doc = new Document();
doc.LoadFromFile("Mydoc.docx");

for (int i = doc.Sections[0].Paragraphs.Count / 2; i < doc.Sections[0].Paragraphs.Count; i++)
doc.Sections[0].Paragraphs[i].ChildObjects.Clear();

doc.SaveToFile("Mydoc.docx",FileFormat.Docx);


The Idiea is to delete half of my document, Can someone give me an answer or may be a better solution?

long231998
 
Posts: 6
Joined: Mon Mar 12, 2018 5:52 am

Thu Mar 22, 2018 2:41 am

Hello,

Thanks for your post. As I was unable to reproduce the issue on my side, please share us with your input Word document and your expected result file. Then we will provide the demo for you. You could zip them and attach here or send to support@e-iceblue.com.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Mon Mar 26, 2018 8:20 am

Hello,

Greeting from E-iceblue.
How is the issue going?
We will appreciate it if you could give us some feedback.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Tue Apr 24, 2018 4:28 am

Hi, Thank for the feedback and Iam so sorry because i didnt come back in a while.
Here is my file

long231998
 
Posts: 6
Joined: Mon Mar 12, 2018 5:52 am

Tue Apr 24, 2018 6:27 am

Hello,

That's OK. I noticed that your code failed to delete the tables. Because the tables are not under a paragraph, they belong to the Body of a section. Please refer to the below code snippet and try again.
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile(@"bai3.doc");

            for (int i = doc.Sections[0].Body.ChildObjects.Count / 2; i < doc.Sections[0].Body.ChildObjects.Count; i++)
                doc.Sections[0].Body.ChildObjects[i].ChildObjects.Clear();

            doc.SaveToFile("Mydoc.docx", FileFormat.Docx);


Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Thu Apr 26, 2018 7:51 am

Hello,

Did you try the solution I provided? How is it going?
Please give us some feedback at your convenience.

Best wishes,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Mon Apr 30, 2018 7:44 am

Its works! Thank

long231998
 
Posts: 6
Joined: Mon Mar 12, 2018 5:52 am

Mon Apr 30, 2018 9:22 am

Hello,

Thanks for your feedback.
Feel free to contact us if any issues.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc