以下是我写的创建一个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.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 |
|
来自: 实力决定地位 > 《OFFICE相关操作》