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下同样存在此问题)。
与本文相关的文章
- 文本文档怎么转换为html文件,win10系统下如何将文本文档转换为网页
- python3 遍历windows下 所有句柄及窗口名称
- 写Windows应用程序日志(event log)
- Windows PATH变量不起作用
- windows中为终端设置代理
- C#写入错误信息到WINDOWS日志查看器中的应用程序日志
- 64位系统下注册32位dll文件
- 手把手教学:IntelliJ IDEA 2024 Windows版下载安装与插件配置指南
- 64位win7下安装SQL Server 2008(图文解说版)
- windows server 2003 详细安装过程带镜像资源
- 安装windows xp 系统
- 【电脑Windows日常】解决Windows11 无法显示office图标的问题
- win11开机都会显示“由于启动计算机时出现了页面文件配置问题,Windows在你的计算机上创建了一个临时页面文件。所有磁盘驱动器的总页面文件大小可能稍大于你所指定的大小。”-- 已解决亲测
- WinCC中通过脚本禁用或启用Windows快捷键
- Windows 重新安装自带计算器
- [EtherCAT]在Windows中编译并使用开源主站SOEM 1.4.0——2024.07.16
- 禁止 Windows 10 和 Windows Server 自动更新
- thinkpad电脑WiFi图标看不到的解决方案
- excel, vba copying cell between files based on criteria - Stack Overflow
- javascript - By using kendo how to export the grid data to any one of the following files (csv,excel ,Pdf) - Stack Overflow
评论列表(0)
- 暂无评论