无法使用 Excel Interop 安排程序 [英] Can't schedule Program with Excel Interop

查看:80
本文介绍了无法使用 Excel Interop 安排程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C# .NET 中开发了一个控制台程序,它使用 Excel Interop.如果我从命令行运行该程序,它可以在我的开发机器和 Windows Server 2008 中正常运行.

I have developed a console program in C# .NET, that uses Excel Interop. The program works just fine on my development machine and in the windows server 2008, if I run it from command line.

当我尝试安排每天运行的任务时,我遇到了这个烦人的互操作错误:

When I try to schedule a task to run it daily, I got this annoying Interop error:

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"存在并且如果在程序启动时完全关闭,因为如果我尝试在命令行中运行相同的程序,它会按预期结束.

The file 'e:\excel.xls' exists and if completely closed when the program starts, because if I try to run the same program in my command line, it ended as expected.

我还设置了我的任务以管理员身份运行,所以应该不是权限问题.

I also have setup my task to run as Administrator, so it shouldn't be permissions issues.

你能帮我吗?

推荐答案

当您从计划任务执行 Office 自动化时,事情可能会变得有点奇怪,因此我建议尝试不同的用户帐户.

Things can get a bit weird when you do Office Automation from a scheduled task, so I'd suggest trying a different user account.

如果它在您登录时工作,那么我建议设置任务计划程序以在您的帐户下运行它.如果仍然有效,请创建一个与您的帐户具有相同权限的新帐户,并让它在该帐户下运行.

If it works when you're logged in, then I'd suggest setting up the task scheduler to run it under your account. If that still works, then create a new account with the same kind of permissions as your account and have it run under that account.

否则,请尝试以管理员帐户登录并确保应用在以管理员身份登录时运行.例如,也许在用户或类似的第一次交互式登录期间设置了一些 Office.

Otherwise, try logging on as the administrator account and make sure that the app runs when logged in as administrator. For example, maybe there is some bit of Office that gets setup during the first interactive login by the user or similar.

这篇关于无法使用 Excel Interop 安排程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆