Win7、Windows Server 2008下无法在Windows Service中打开一个已经存在的Excel 2007文件问题的解决方案
本地开发工具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, true, true });
抛出异常:
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/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下同样存在此问题)。
与本文相关的文章
- 【FTP】linux FTP传文件到windows|ftp的常用命令
- 文件钩子——监听Windows文件操作
- Windows下使用Docker编译Android系统源代码
- Windows Server 出现多个匿名登陆用户的问题解决
- Windows 中一个应用程序的启动过程
- 用GHOST快速重装Windows系统
- 快速容易地处理Windows、Mac 和Linux系统中文件路径问题
- Windows关闭错误报告弹窗
- (护眼)Windows 10 护眼小工具推荐
- windows server 2019 更新补丁
- windows10与Linux子系统文件目录相互访问
- Windows使用内存映射文件
- Windows2008 DFS 分布式文件系统安装笔记
- 如何在Windows下部署Linux子系统?
- Python远程获取Windows主机信息
- windows 环境下c++系统栈大小调整
- Windows获取系统分辨率4种方式总结
- Windows下配置环境变量
- 向Windows 7安装镜像添加设备驱动程序
- windows系统变安卓系统
评论列表(0)
- 暂无评论