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下同样存在此问题)。
与本文相关的文章
- windows下安装redis和redis扩展
- 通过Windows进程ID获取窗口句柄
- jenkins自动构建批处理命令-windows
- 破解windows密码
- Windows快速打开服务
- windows修改默认登陆用户
- 黑苹果与Windows双系统时间不一致的解决办法
- windows中为终端设置代理
- Windows 11 家庭中文版更改用户名
- C#写入错误信息到WINDOWS日志查看器中的应用程序日志
- 【windows使用技巧#0】ISO镜像,OEM、Retail这些到底是什么意思
- 手把手教学:IntelliJ IDEA 2024 Windows版下载安装与插件配置指南
- 机械革命电脑无法退出BIOS界面的解决方案
- windows安装win7虚拟机教程(保姆教程+保底手段)
- win11开机都会显示“由于启动计算机时出现了页面文件配置问题,Windows在你的计算机上创建了一个临时页面文件。所有磁盘驱动器的总页面文件大小可能稍大于你所指定的大小。”-- 已解决亲测
- 如何备份U盘文件?教您4个简单方法
- 此计算机当前已将连接限制为cmcc,完美的解决方案:猎豹wifi常见问题的解决方案...
- thinkpad电脑WiFi图标看不到的解决方案
- javascript - By using kendo how to export the grid data to any one of the following files (csv,excel ,Pdf) - Stack Overflow
- javascript - NodeJS, Windows, wmic stdin - Stack Overflow
评论列表(0)
- 暂无评论