Hi team,
I need to check current paragraph and need to point to next node based on some value. Like if the current paragraph is “Some header” and based on matching value i need to take next table data.
Hi team,
I need to check current paragraph and need to point to next node based on some value. Like if the current paragraph is “Some header” and based on matching value i need to take next table data.
PFA of sample Document.
In attached document we need to search for “1. OBJECTIVES AND ENDPOINTS Data” and point to next table and extract table data.
sampleDOC.docx (23.6 KB)
@kkumaranil485 You can achieve what you need using Node.NextSibling
property or Node.NextPreOrder
method. Please see our documentation to learn more about Aspose.Words Document Object Model. Here is a simple code example that demonstrates the technique:
Document doc = new Document("C:\\Temp\\in.docx");
// Get the paragraph you are interested in.
Paragraph paragraph = doc.GetChildNodes(NodeType.Paragraph, true)
.Cast<Paragraph>().Where(p => p.ToString(SaveFormat.Text).Trim().StartsWith("OBJECTIVES AND ENDPOINTS Data")).First();
Table table = GetNextTable(paragraph);
private static Table GetNextTable(Node node)
{
Node currentNode = node;
while (currentNode != null && currentNode.NodeType != NodeType.Table)
currentNode = currentNode.NextPreOrder(node.Document);
return currentNode as Table;
}
Hi,
How can we skip to next table if the table we need is 2nd table from next table.
@kkumaranil485 You can simply take the next table:
Table firstTable = GetNextTable(paragraph);
if (firstTable != null)
{
Table secondTable = GetNextTable(firstTable.NextSibling);
// .....
// Do something with the second table.
}