Excel 2007 automation on top of a Windows Server 2008 x64

今天在一个客户这边出来一个windows service的问题。这个service需要启动excel程序,并且对一些excel文件做一些操作。

环境是:windows server 2008 x64+Excel 2007

总是报告错误:(类似下面这样)

Service cannot be started. System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot access the file 'c:\temp\test.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.

代码怎么看都是可以的,反复调试了service,问题最后解决了,大致有如下几点

 

第一步:在服务器添加有关的一个目录

这个方案参考了http://social.msdn.microsoft.com/Forums/en-US/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91?prof=required

This solution is ...

・Windows 2008 Server x64
  Please make this folder.

  C:\Windows\SysWOW64\config\systemprofile\Desktop

・Windows 2008 Server x86

  Please make this folder.

  C:\Windows\System32\config\systemprofile\Desktop

  ...instead of dcomcnfg.exe.

This operation took away office automation problems in my system.

A Desktop folder seems to be necessary in the systemprofile folder to open file by Excel.

It disappears from Windows2008, Windows2003 had the folder,
and I think it cause this error.

I think it is safer than "registry hack".

If you try this solution, please let me know results.

 

第二步:设置服务与桌面交互

image

 

第三步:关闭服务器的UAC(这一步至关重要,调试了一个下午,就是因为这个问题卡住)

 

image

posted @   陈希章  阅读(683)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· winform 绘制太阳,地球,月球 运作规律
· 上周热点回顾(3.3-3.9)
历史上的今天:
2010-04-22 MTOM效率测试
2010-04-22 Infopath 2010的变化
2010-04-22 MOSS 2010:如何为列表设计Infopath表单用于编辑和显示
2010-04-22 MOSS 2010:为视图添加参数显示的功能
2010-04-22 MOSS 2010:通过SharePoint Designer定制列表项的条件格式
2010-04-22 MOSS 2010:列表编辑变得更加容易
2009-04-22 数据搜索算法
点击右上角即可分享
微信分享提示