Hi Team,
How to extract the paragraph below the table.
Please find the below input and Expected output.
Expected_output93.docx (13.0 KB)
Input_Training_Audience.docx (16.2 KB)
@Raju123 You can use Node.NextSibling property to get the paragraph after the table. Please see the following code for example:
// Get the table.
Table table = doc.FirstSection.Body.Tables[0];
// Get the paragraph after the table.
Paragraph paragraph = (Paragraph)table.NextSibling;
@alexey.noskov I used above code but I am getting cast error. Kindly help me.
System.InvalidCastException: ‘Unable to cast object of type ‘Aspose.Words.BookmarkEnd’ to type ‘Aspose.Words.Paragraph’.’
@Raju123 It looks like in your case the next node after the table is BookmakrEnd
. You can use DocumentExplorer demo application to explore document structure.
Also, you can use Node.NodeType
property to check the type of the node to avoid cast exceptions. For example:
// Get the table.
Table table = doc.FirstSection.Body.Tables[0];
// Get the paragraph after the table.
Node nextNode = table.NextSibling;
while (nextNode != null && nextNode.NodeType != NodeType.Paragraph)
nextNode = nextNode.NextSibling;
Paragraph paragraph = (Paragraph)nextNode;