【发布时间】:2019-08-10 02:02:06
【问题描述】:
我尝试在 C# 中打开一个 Excel 文件,但出现此错误:
System.Runtime.InteropServices.COMException HResult=0x800A03E
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using excel = Microsoft.Office.Interop.Excel;
namespace Example_Reading_A_File_From_Excel
{
class Program
{
static void Main(string[] args)
{
excel.Application x1app = new excel.Application();
excel.Workbook x1workbook = x1app.Workbooks.Open(@"D:\saniaertest.xlsx");
excel._Worksheet x1worksheet = x1workbook.Sheets[1];
excel.Range x1range = x1worksheet.UsedRange;
string website;
for(int i = 1; i <= 3; i++)
{
website = x1range.Cells[i][9].value2;
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl(website);
Thread.Sleep(30);
driver.Close();
}
}
}
}
通常它应该打开 Excel 文件并打开 Chrome 浏览器并导航到第 9 列中列出的所有 URL。但就像之前所说的,我只得到错误:
System.Runtime.InteropServices.COMException HResult=0x800A03E
它说找不到工作簿。
【问题讨论】:
-
仅仅异常类型是不够的。提供完整的异常消息和相应的 HRESULT 值。
-
你永远不会退出
excel.Application x1app。另见here -
System.Runtime.InteropServices.COMException HResult=0x800A03EC
-
@oherby 您刚刚在聊天中输入的内容与您在问题中的内容不同。请编辑您的问题并澄清。
-
也许找不到工作簿...因为这就是错误消息所述的内容。您是否确认工作簿在该路径中并且您没有拼写错误?工作簿是否以 .xls 或 .xlsx 结尾?等
标签: c# excel selenium selenium-webdriver