我开发了一个使用Excel互操作的C# .NET控制台程序。在我的开发机和Windows Server 2008上,如果我从命令行运行它,程序可以正常工作。
但是,当我尝试安排一个每日运行的任务时,我遇到了这个烦人的Interop错误:
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'文件后才能启动,因为如果我尝试在命令行中运行相同的程序,它会如预期一样结束。
我还将我的任务设置为以管理员身份运行,因此不应该存在权限问题。
你能帮助我吗?