如何在C#.net中从microsoft word读取合并表数据

如何在C#.net中从microsoft word读取合并表数据,c#,office-interop,C#,Office Interop,这是我从ms word文件读取表格数据的代码, 这在非合并表中非常有效,但我在合并表中有数据,这段代码不起作用 请帮忙 private void Readfiles() { var word = new Word.Application(); object miss = System.Reflection.Missing.Value; object path = @"C:\Users\gd-08\Deskto

这是我从ms word文件读取表格数据的代码, 这在非合并表中非常有效,但我在合并表中有数据,这段代码不起作用

请帮忙

private void Readfiles()
        {
            var word = new Word.Application();
            object miss = System.Reflection.Missing.Value;
            object path = @"C:\Users\gd-08\Desktop\Маршруты движения (только первый вход и последний выход).rtf";
            object readOnly = true;

var docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);

            //Processing all tables in the documents
            var firstTable = docs.Tables[1];

            var c = firstTable.Rows.Count;


            foreach (Word.Row row in firstTable.Rows)
            {


                List<string> cellValues = new List<string>();
                foreach (Word.Cell cell in row.Cells)
                {
                    string cellContents = cell.Range.Text;

                    // add the cell contents to the array, but remove the strange termination character on the end of the data
                    cellValues.Add(cellContents.Remove(cellContents.Length - 1));
                }

                // the first row is the column header

                //AddWordTableRow(cellValues);

            }

            docs.Close();
            word.Quit();
        }
    }
private void Readfiles()
{
var word=新单词.Application();
对象未命中=System.Reflection.Missing.Value;
对象路径=@“C:\Users\gd-08\Desktop\Мжжжжжжжаааааааажаааааа;
对象只读=真;
var docs=word.Documents.Open(参考路径、参考未命中、参考只读、参考未命中、参考未命中、参考未命中、参考未命中、参考未命中、参考未命中、参考未命中、参考未命中、参考未命中、参考未命中、参考未命中、参考未命中);
//处理文档中的所有表
var firstTable=docs.Tables[1];
var c=firstTable.Rows.Count;
foreach(firstTable.Rows中的Word.Row行)
{
List cellValues=新列表();
foreach(行中的Word.Cell单元格)
{
字符串cellContents=cell.Range.Text;
//将单元格内容添加到数组中,但删除数据末尾的奇怪终止字符
添加(cellContents.Remove(cellContents.Length-1));
}
//第一行是列标题
//AddWordTableRow(单元格值);
}
docs.Close();
word.Quit();
}
}

尝试使用
for
foreach
处理表格,看看您在读取数据时是否会遇到问题。word中的表更接近多维数组,因此很难使用em。这可能适合您