False System.Runtime.InteropServices.COMException,尽管文件存在

本文关键字:文件 存在 COMException System Runtime InteropServices False | 更新日期: 2023-09-27 18:15:41

我一直试图通过控制台打开EXCEL文件,但每次我得到以下异常:

System.Runtime.InteropServices.COMException

文件不存在或丢失。路径是正确的。下面是我得到异常的代码:

string path = @"C:'User'Desktop'TerritoryFile.xlsx";
var file = new Excel.Application();
file.Visible = false;
var wb = file.Workbooks.Open(path);

除了路径错误,还有其他原因吗

False System.Runtime.InteropServices.COMException,尽管文件存在

试试这个

string path = @"your file path ";
var file = new Microsoft.Office.Interop.Excel.Application();
file.Visible = false;
var wb = file.Workbooks.Open(path);