如何在c#winforms中读取MS Word表?

问题描述 投票:-1回答:1

我在MS Word中有一个包含8列的表。 7列是基于文本的,1列是图像。我想逐行读取所有值并在窗体上的控件中显示。我试过以下代码给我一个错误。此代码也适用于我认为的文字

           w = new Word.Application();
        var document = w.Documents.Open(tbWordFile.Text.Trim());
for (int iCounter = 1; iCounter <= document.Tables.Count; iCounter++)
        {
            foreach (Row in document.Tables[iCounter].Rows)
            {
                foreach (Cell aCell in aRow.Cells)
                {
                    currLine = aCell.Range.Text;
                    //Process Line
                }
            }
        }

“行”变量出现错误是“由于其保护级别,行无法访问”

c# .net winforms
1个回答
-1
投票
foreach (Row in document.Tables[iCounter].Rows)

你正在迭代行,你的每个项目是什么?你声明Row没有变量名。这应该是这样的:

  foreach (Row aRow in document.Tables[iCounter].Rows)
© www.soinside.com 2019 - 2024. All rights reserved.