c# - 使用 C# selenium web 驱动程序从 excel 读取数据时出现异常
问题描述
我在使用 selenium Web 驱动程序从 Excel 读取数据时遇到问题。我使用过“Microsoft.Office.Interop.Excel”,并且在运行我的代码时发现了该异常
System.Runtime.InteropServices.Exception:Excel 无法访问“下载”。该文档可以是只读的或加密的。 在此处输入图像描述
这是我使用的代码 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");
}
}
}
解决方案
只是为了其他人清楚:
工作簿 xlWorkBook = xlApp.Workbooks.Open(@"C:\Users\kkhatab\Desktop\3.0.0\Cube.Portal.Regression_for_issuesTests\bin\Downloads");
您试图在此处打开文件夹而不是文档。
推荐阅读
- django-rest-framework - 从 Angular 5 前端发布到 Django Rest Framework 后端
- dart - 具有透明背景的颤动角半径
- java - 你如何使一个按钮依赖于另一个按钮来加载android中的特定链接?爪哇
- java - 只能在java中创建一个扩展类,其他的显然必须在自己的文件中
- firebase - 用于位置的 Polymer Firebase 绑定
- javascript - 如何在 Angular js 控制器中重构 10000 行代码?
- python - Python 3 中未初始化默认函数参数
- python - Python:将数组元素与浮点数进行比较,得到一个布尔列表
- c# - 列表及其所有嵌套列表值的 Linq 平均值
- php - Laravel:对多个图像进行图像验证不起作用