【发布时间】:2011-09-09 09:49:11
【问题描述】:
我收到以下错误:
无法创建 TestProject.TestClass 类的实例。错误:System.Runtime.InteropServices.COMException:找不到“D:\Automation\TestProject\OBJECT_DEFINITIONS.XLS”。检查文件名的拼写,并验证文件位置是否正确。如果您尝试从最近使用的文件列表中打开该文件,请确保该文件未被重命名、移动或删除。
错误堆栈跟踪:
Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter , 对象 AddToMru, 对象本地, 对象 CorruptLoad)
C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\TestProject\TestLibrary.cs 中的 TestProject.TestLibrary.GetObjectDeclarations(String sModule):第 133 行
C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\TestProject\TestClass.cs 中的 TestProject.TestClass..ctor():第 51 行
代码:
using Excel = Microsoft.Office.Interop.Excel;
namespace TestProject
{
[TestClass]
public class TestLibrary
{
public string[] arrObj = new string[19];
public string[] arrConfig = new string[12];
public string sobjfile;
.
.
.
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(sobjfile, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
我想知道当我将OBJECT_DEFINITIONS.XLS 存储在C:\ 中时,为什么找不到D:\Automation\TestProject\OBJECT_DEFINITIONS.XLS 的错误提示
【问题讨论】:
-
在哪里可以看到您的这个 excel 文件的路径?
-
我不确定。我所看到的只是未分配任何路径的变量 sobjfile。我也试过 public string sobjfile = 'C:\\OBJECT_DEFINITIONS.XLS"; 但得到同样的错误
标签: c# excel comexception vba