Win7、Windows Server 2008下无法在Windows Service中打开一个已经存在的Excel 2007文件问题的解决方案

我用asp.net 开发一个把word上传到服务器上然后把word转换成html
本地开发工具vs2008 ,office为2003, 环境是XP系统,在本地运行正常,也没遇到什么错误。
  但当我放入到服务器上接着就一串的错误出来了。
先报错:
从 IClassFactory 为 CLSID 为 {00020906-0000-0000-C000-000000000046} 的 COM 组件创建实例失败,原因是出现以下错误: 8001010a。
这个很好弄,是office没设权限。进入"开始"->"运行"中输入dcomcnfg.exe启动"组件服务" 中的DCOM中找到00020906-0000-0000-C000-000000000046 标识的分配权限。这个网上有很多。责任就不多说了。

以下是我写的创建一个word并打开,为了方便转换用的
#region  文件格式转换
// 请引用Microsoft.Office.Interop.Word
ApplicationClass word  =   new  ApplicationClass();
Type wordType 
=  word.GetType();
Documents docs 
=  word.Documents;

//  打开文件
Type docsType  =  docs.GetType();
object  fileName  =  wordPath;  // "f:\\cc.doc";
Document doc  =  (Document)docsType.InvokeMember( " Open " , BindingFlags.InvokeMethod,  null , ( object )docs,  new  Object[] { fileName,  true true  });
在执行到
Document doc = (Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, (object)docs, new Object[] { fileName, truetrue });
抛出异常:
System.Runtime.InteropServices.COMException (0x800A141F): Word 无法读取文档,文档可能损坏。
请尝试下列方法:
* 打开并修复文件。
* 用文本恢复转换器打开文件。

根据网上搜索InvokeMember方法用法在msdn上看到它的运行平台支持
Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2
InvokeMember方法说明:http://msdn.microsoft.com/zh-cn/library/system.reflection.ireflect.invokemember.aspx
我的服务器系统为Windows Server 2008 64位。看到这儿知道是系统问题,
于是在网上搜索,终于找到一篇文章写的和我问题一样得到解决方法
如果系统为Windows 2008 Server x64 
   在下面路径中创建一个Desktop空的文件夹
   C:\Windows\SysWOW64\config\systemprofile\Desktop
・如果系统为Windows2008Serverx86
在下面路径中创建一个 Desktop空的文件夹
C:\Windows\System32\config\systemprofile\Desktop
至于原因。这个就不太清楚了。如果有了解的可以告诉我以下,谢谢!
开发环境是Win7、Visual Studio .Net 2008(Windows Server 2008下同样存在此问题)。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值