I have a Word document.
a.docx (13 KB)
I want to get data from each table inside the table.
How to know if a table is inside a table using the Aspose Word.
Thank you!
I have a Word document.
a.docx (13 KB)
I want to get data from each table inside the table.
How to know if a table is inside a table using the Aspose Word.
Thank you!
@quanghieumylo, could you try the following code example and check whether it suits your needs:
Document doc = new Document("a.docx");
int tableIndex = 0;
foreach (Table t in doc.GetChildNodes(NodeType.Table, true))
{
// Inner tables has cell as a parent node.
if (t.ParentNode is Cell)
{
Console.WriteLine($"Inner table: {tableIndex}");
GetTableData(t);
tableIndex++;
Console.WriteLine("");
}
}
static void GetTableData(Table t)
{
int rowIndex = 0;
foreach (Row row in t.Rows)
{
int cellIndex = 0;
foreach (Cell cell in row.Cells)
{
Console.WriteLine($"Row: {rowIndex} Cell: {cellIndex}");
Console.WriteLine(cell.GetText());
cellIndex++;
}
rowIndex++;
}
}
It is perfect, thanks!
Hey bro, I have one more question.
How do I clone anything between the two words “table2” and “table3” into a new document?
a.docx (13.2 KB)
Thank you. I thought I had to create a new topic to get a reply, so I posted it in two places.