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 Jun 04, 2025 4:09 am

We are using the following version of Spire:

>Spire.Office.10.2.0
>Spire.DOC: 13.2.3.3020
>(.NET Framework 2.0)

I would like to check if the Word file contains any shape objects, and if it does, I would like to execute specific processing. Please provide examples of how to program this using APIs, as well as the scope of what can be checked.

The target items we intend to obtain are as shown in the attached capture.

Previously, I made the same inquiry regarding Excel in the following topic. This time, I would like to ask about the case for Word.
https://www.e-iceblue.com/forum/the-print-object-setting-is-not-enabled-t13601.html

Thank you for your assistance.

sxi123123123
 
Posts: 29
Joined: Thu Mar 06, 2025 3:09 pm

Wed Jun 04, 2025 10:34 am

Hello,

Thanks for your inquiry.
Spire.Doc can acquire all ShapeObjects. Here’s how to get ShapeObjects for your reference:
Code: Select all
 //load a word document
 Document  doc = new Document();
 doc.LoadFromFile(@"test.docx");
 //shape count
 int count = 0;
 //loop through all sections
 for (int i = 0; i < doc.Sections.Count; i++)
 {
     Section section = doc.Sections[i];
     //loop through all tables
     for  (int j = 0; j < section.Tables.Count; j++)
     {
         Table table  = section.Tables[j] as Table;
         for (int k = 0; k < table.Rows.Count; k++)
         {
             TableRow row = table.Rows[k];
             for (int l = 0; l < row.Cells.Count; l++)
             {
                 TableCell cell = row.Cells[l];
                 for (int m = 0; m < cell.Paragraphs.Count; m++)
                 {
                     Paragraph paragraph = cell.Paragraphs[m];
                     for (int n = 0; n < paragraph.ChildObjects.Count; n++)
                     {
                         if (paragraph.ChildObjects[n] is Shape)
                        {
                             Shape shape = paragraph.ChildObjects[n] as Shape;
                             count++;
                             Console.WriteLine("Shape found in paragraph: " + count);
                         }
                     }
                 }
             }
         }

     }
     //loop through all paragraphs
     for (int j = 0; j < section.Paragraphs.Count; j++)
     {
         Paragraph paragraph = section.Paragraphs[j];
         //loop through all child objects
         for (int k = 0; k < paragraph.ChildObjects.Count; k++)
         {
             //get the child object
             DocumentObject obj = paragraph.ChildObjects[k];
             if (obj is Shape)
             {
                 Shape shape = (Shape)obj;
                 count++;
                 Console.WriteLine("Shape found in paragraph: "+count );
             }
         }
     }
 }
 doc.Close();

If it is convenient for you, you can provide the document from which you need to obtain the graphics, and we will provide the corresponding code based on your document.
If you have any other questions later, please contact us in time. Thank you in advance.

Sincerely,
Tommy
E-iceblue support team
User avatar

Tommy.Tang
 
Posts: 85
Joined: Mon Apr 21, 2025 7:05 am

Return to Spire.Doc

cron