使用Windows Service打开Excel文件 [英] Using windows service to open an Excel file

查看:474
本文介绍了使用Windows Service打开Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用IIS应用程序启动Windows服务,然后打开了(2003或2007)Excel文件.当我的Excel加载项收到打开"消息时,它将尝试使用以下代码打开Excel文件.
Microsoft.Office.Interop.Excel.Application.Workbooks.Open(fName,False,1)''fName是文件的路径

然后我得到了一个例外:
"Microsoft Office Excel无法访问文件" C:\ ... \ Book2003.xls".有几种可能的原因:
•文件名或路径不存在.
•该文件正在被另一个程序使用.
•您要保存的工作簿与当前打开的工作簿具有相同的名称."

该文件未使用,并且路径正确.而且我已向所有人授予对该文件的完全许可.我正在使用Windows 7 64位,Excel 2007 sp2和IIS7.文件夹"C:\ Windows \ SysWOW64 \ config \ systemprofile \ Desktop"确实存在.
有人可以帮忙吗?

谢谢

Hi,

I am using an IIS application to launch a windows service which then opens a (2003 or 2007) Excel file. When my Excel add-in receive the ''open'' message, it will try use the following code to open the Excel file.
Microsoft.Office.Interop.Excel.Application.Workbooks.Open(fName, False, 1) ''fName is the path to the file

Then I got the exception:
"Microsoft Office Excel cannot access the file ''C:\...\Book2003.xls''. There are several possible 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 a currently open workbook."

The file is not in use and the path is correct. And I have given everyone full permission on that file. I am using windows 7 64-bit, Excel 2007 sp2 and IIS 7. The folder "C:\Windows\SysWOW64\config\systemprofile\Desktop" does exist.
Could anybody help please?

Thanks

推荐答案

Chas,

原谅我,但是您的解决方案似乎有点奇怪.您使用IIS应用程序启动Windows服务吗? Windows服务旨在在后台连续运行.对于您的应用程序而言,更好的体系结构是让Windows服务在后台连续运行,让iis应用程序通过webservice调用连接到Windows服务(该Web服务将托管在Windows服务中).

关于您的问题,可能有很多错误.例如,Windows服务在哪个用户帐户下运行?此帐户是否具有足够的权限来打开excel文件?同样,通常Windows服务也不允许显示用户界面.这是Windows服务上的一个选项,允许与桌面交互"

您可以使用进程监视器之类的工具来检查文件是在哪个帐户下打开的. >
希望这会有所帮助.
Hi Chas,

Forgive me, but your solution seems a bit strange. You use a IIS application to launch a windows service? Windows service are intended to run continously in the background. A better architecture for you application would be to have the windows service continuously running in the background, have the iis application connect to the windows service using a webservice call (the webservice would be hosted in the windows service).

Regarding you question, there could be a lot of thing wrong. For example under which user account is the windows service running? Does this account have enough rights to open the excel file? Also normally windows services are not allowed to show an user interface. It is a option on a windows service "to allow interaction with the desktop"

You could use a tool like process monitor to check under which account the file is being opened.

Hope this helps.


这篇关于使用Windows Service打开Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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