使用C#selenium web驱动程序从excel读取数据的一个例外

时间:2018-05-22 08:49:46

标签: c# excel

使用selenium web驱动程序从Excel读取数据时遇到问题。我使用了“Microsoft.Office.Interop.Excel”,在运行我的代码时发现了异常

System.Runtime.InteropServices.Exception:Excel无法访问“下载”。该文档可能是只读的或加密的。 enter image description here

这是我用过的代码   public void sch_issue_1958M()         {

        Application xlApp = new Application();
        Workbook xlWorkBook = xlApp.Workbooks.Open(@"C:\Users\kkhatab\Desktop\3.0.0\Cube.Portal.Regression_for_issuesTests\bin\Downloads");
        Worksheet xlWorkSheet = new Worksheet();
        xlWorkSheet = xlWorkBook.Sheets[1];
        Range xlRange = xlWorkSheet.UsedRange;
        int rowCount = xlRange.Rows.Count;
        int colCount = xlRange.Columns.Count;
        for (int i = 1; i <= rowCount; i++)
        {
            for (int j = 1; j <= colCount; j++)
            {
                //new line
                if (j == 1)
                    Console.Write("\r\n");

                //write the value to the console
                if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null)
                    Console.Write(xlRange.Cells[i, j].Value2.ToString() + "\t");


            }


        }
    }

1 个答案:

答案 0 :(得分:0)

为了清楚其他人:

工作簿xlWorkBook = xlApp.Workbooks.Open(@“C:\ Users \ kkhatab \ Desktop \ 3.0.0 \ Cube.Portal.Regression_for_issuesTests \ bin \ Downloads”);

您正在尝试在此处打开文件夹而不是文档。