Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用C#selenium web驱动程序从excel读取数据时出现异常_C#_Excel - Fatal编程技术网

使用C#selenium web驱动程序从excel读取数据时出现异常

使用C#selenium web驱动程序从excel读取数据时出现异常,c#,excel,C#,Excel,我在使用selenium web驱动程序从Excel读取数据时遇到问题。我使用了“Microsoft.Office.Interop.Excel”,运行代码时发现了该异常 System.Runtime.InteropServices.Exception:Excel无法访问“下载”。文档可以是只读的或加密的。 这是我用过的代码 公共无效SCHU发行号1958M() { Application xlApp = new Application(); Workbook x

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

System.Runtime.InteropServices.Exception:Excel无法访问“下载”。文档可以是只读的或加密的。

这是我用过的代码 公共无效SCHU发行号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");


            }


        }
    }
Application xlApp=新应用程序();
工作簿xlWorkBook=xlApp.Workbooks.Open(@“C:\Users\kkhatab\Desktop\3.0.0\Cube.Portal.returnal\u用于发布测试\bin\Downloads”);
工作表xlWorkSheet=新工作表();
xlWorkSheet=xlWorkBook.Sheets[1];
范围xlRange=xlWorkSheet.UsedRange;
int rowCount=xlRange.Rows.Count;
int colCount=xlRange.Columns.Count;

对于(int i=1;i,仅为了让其他人更清楚:

工作簿xlWorkBook=xlApp.Workbooks.Open(@“C:\Users\kkhatab\Desktop\3.0.0\Cube.Portal.returnal\u用于发布测试\bin\Downloads”)


您试图在此处打开的是文件夹而不是文档。

屏幕截图上的异常显示:您试图打开的是文件夹而不是文件。请看第二行。该文件不应该像(@“C:\Users\kkhatab\Desktop\3.0.0\Cube.Portal.returnal\u for_issuests\bin\Downloads\myFile.xlsm?还有一件事:您的代码正在使用”“Microsoft.Office.Interop.Excel”,而不是“Selenium”,非常感谢大家。它很有效now@vasily.sib,是的,代码使用“Microsoft.Office.Interop.Excel”,这是使用selenium的问题的一部分