Access column index of the current cursor location in document

In need to access the current location of the cursor, if the cursor is in a table cell.
I got to the row number of the cell in the table but not column …

Node startNode = builder.CurrentNode;
if (((Paragraph)startNode.ParentNode).ParentNode.NodeType == NodeType.Cell)
{
    Cell cell = (Cell)(((Paragraph)startNode.ParentNode).ParentNode);
    int rowCellIndex = cell.ParentRow.IndexOf(cell);

---------------
Note: The table could be with blank values with no headers (column names)
It could be of any number of columns/rows.

Thanks for your help.

Hi there,

Thanks for your inquiry. Please use the following code to get the desired output.

DocumentBuilder builder = new DocumentBuilder(doc);
Node startNode = builder.CurrentNode;
Row row = (Row)startNode.GetAncestor(NodeType.Row);
if (row != null)
{
    Cell cell = (Cell)(((Paragraph)startNode.ParentNode).ParentNode);
    int rowCellIndex = row.Cells.IndexOf(cell);
}

Please note that Aspose.Words mimics the same behavior as MS Word does. By 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 there is no column concept in MS Word’s table.

Yes, thanks for the reply,
however, I am looking for COLUMN index.
Thanks,

Hi there,

Thanks for your inquiry. There is no column concept in MS Word’s table.

By 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, if you imagine first row with one wide cell and second row with two narrow cells, then looking at this document the cell in the first row will appear horizontally merged. But it is not a merged cell; it is just a single wide cell.

Another perfectly valid scenario is when the first row has two cells. First cell has CellMerge.First and second cell has CellMerge.Previous, in this case it is a merged cell. In both cases, the visual appearance in MS Word is exactly the same. Both cases are valid.

However, you can get the index of cell using CellCollection.IndexOf property. Please let us know if you have any more queries.