How to access columns in a table that have different cell widths from MS Word

若如初见. 提交于 2019-12-01 05:24:46

Instead of using a foreach loop in your second loop, can you instead use a for loop like so to iterate over all cells:

        for (int r = 1; r <= rng.Tables[1].Row.Count; r++)
        {
            for (int c = 1; c <= rng.Tables[1].Columns.Count; c++)
            {
                try
                {
                    Cell cell = table.Cell(r, c);
                    //Do what you want here with the cell
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("The requested member of the collection does not exist."))
                    {
                       //Most likely a part of a merged cell, so skip over.
                    }
                    else throw;
                }
            }
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!