How to loop through table columns to display?the table row is unchanged
thanks!
How to loop through table columns to display?the table row is unchanged
thanks!
Hi
Thanks for your inquiry. Actually there is no “column” concept in the Word table. By design Microsoft Word design rows in a table in a Microsoft Word document are completely independent. It means each row can have any number of cells of any width.
So you cannot loop through columns in MS Word table. However, you can loop through cells in each row in the table. If each row of the table contains the same number of cells, you can suppose that cells with the same index within the rows are in the same column.
Hope this helps.
Best regards.
hi
how to loop through cells in each row in the table?Please give me an example and code.
thanks
Hi
Thanks for your request. Here is simple code example that shows how to loop through all cells:
// Get your table form the document.
Table table = doc.FirstSection.Body.Tables[0];
// loop through all rows:
foreach (Row row in table.Rows)
{
// Loop through all cells in the current row.
foreach (Cell cell in row.Cells)
{
// Do something....
}
}
Hope this helps.
Best regards,