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.

Tue Sep 06, 2022 11:14 am

Hi Team,

I'm getting error while assigning Paragraph.OwnerTextBody.Owner to section.
Please find the code below
Dim fieldParagraph As Paragraph = gridField.OwnerParagraph
Dim section As Section = fieldParagraph.OwnerTextBody.Owner // Getting Error Here(Unable to cast object of type 'Spire.Doc.TableRow' to type)

Document which contains nested tables.

Please let me know, If I missing anything.

Thank you in advance

Regards
Muthukumar K

SpireLMS
 
Posts: 2
Joined: Tue Sep 06, 2022 11:10 am

Wed Sep 07, 2022 7:38 am

Hi Muthukumar,

Thanks for your inquiry.

Based on your description and code, I speculate that in the current case, the document hierarchy is as follows:
Code: Select all
Document->Section->Body->Table->TableRow->TableCell->Paragraph


So fieldParagraph.OwnerTextBody is actually a cell object in the table.
If you need to get the current Section, you should refer to the following code:

Code: Select all
Dim tableCell As TableCell=fieldParagraph.OwnerTextBody
Dim tableRow As TableRow=tableCell .Owner
Dim table As Table=tableRow.Owner
Dim section As Section=table.OwnerTextBody.Owner


Of course, if there are more levels of nested tables in your document. Then the hierarchy will look like below. You need to look up correspondingly to get the Section.
Code: Select all
Document->Section->Body->Table->TableRow->TableCell->Table(2)->TableRow->TableCell->Table(3)->....->TableCell->Paragraph

Hope it can help you. If there is any other question, just feel free to contact us.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Thu Oct 20, 2022 12:53 pm

Hi Andy,

Thanks for your response :)

I have tried with your provided solution. But, Still I'm getting error like "Value of the 'Body' cannot be converted to 'TableCell'"
And also "Owner is not a member of Table Cell".

Please let me know, If I missing anything.

Thank you in advance.

Regards,
Muthukumar K

SpireLMS
 
Posts: 2
Joined: Tue Sep 06, 2022 11:10 am

Fri Oct 21, 2022 9:52 am

Hello,

Thanks for your feedback.
To help us reproduce your issue and work out a solution for you, please offer the following message, thanks for your assistance in advance.
1) Your full test code that can reproduce your issue.
2) The test document, you can attach here or send it to us via email(sales@e-iceblue.com)
3) Application type, such as Console App, .NET Framework 4.8.
4) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 973
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.Doc