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下同样存在此问题)。
与本文相关的文章
- VS中C4996 ‘fopen‘: This function or variable may be unsafe. Consider using fopen_s instead.的解决方案
- Spring Boot:Consider defining a bean of type ‘*.*.*‘ in your configuration解决方案
- Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper.........[已解决]
- 解决Mac安装Adobe软件错误代码501问题(PS AI AE PR)mac安装Adobe软件报错501解决方案
- .ps后缀文件打开
- 【Linux】查看软件(或文件)安装(或下载)的位置
- .ps格式的文件怎么打开?方法:通过GSview打开或将.ps转换成.pdf
- ps保存psd后图层全没了_Photoshop文件不显示图层
- .ps文件(ghostscript转换pdf)
- U盘安装Linux系统报dracut-initqueue错误,解决方案
- U盘装linux总是不行,U盘安装Linux安装报错及解决方案
- 计算机itunes无法安装,手把手给你细说win7系统电脑无法安装itunes的解决方案
- 在windows XP系统下编译和使用ffmpeg
- Win7 Windows XP 下载提示框
- 字体文件夹在哪?xpwin7win8win10系统字体文件夹位置
- windows8下U盘安装ubuntu,非wubi安装,遇到的问题以及解决方案
- 笔记本电脑代理服务器有问题或者地址有误解决方案(已解决)
- WIFI手机使用正常电脑使用卡顿解决方案
- 如何查看电脑连接过的WiF的密码(Windows版)
- HarmonyOS学习--初次下载安装和配置环境(windows)
评论列表(0)
- 暂无评论