我在 C# .NET 中开发了一个使用 Excel 互操作的控制台程序。如果我从命令行运行,该程序在我的开发机器和 windows server 2008 上运行良好。
当我尝试安排一个任务每天运行它时,我得到了这个烦人的互操作错误:
02/11/2011 00:30:05,000 [1] FATAL My.Program [(null)] - Unable to Microsoft Office Excel open file 'E:\excel.xls' by one of several reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as the currently opened book.
System.Runtime.InteropServices.COMException (0x800A03EC): Unable to access the Microsoft Office Excel file 'E:\excel.xls' by one of several reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as the currently opened book.
in Microsoft.Office.Interop.Excel.Workbooks.Open (String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, IgnoreReadOnlyRecommended Object, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
文件 'e:\excel.xls' 存在,如果在程序启动时完全关闭,因为如果我尝试在命令行中运行相同的程序,它会按预期结束。
我还设置了我的任务以管理员身份运行,所以它不应该是权限问题。
你能帮助我吗?