• WPF调用office2010的ppt出错


     

    各位热爱WPF编程小伙伴不可避免的会遇到将ppt嵌入到自己编写的软件,可是有时候会遇到错误,此错误值出现在卸载office2013并安装其他版本office时候会出现。这是由于某些机器上office不能完全卸载造成的,倒是com口不能释放完全。由于office2013在某些机器环境下卸载不完全,在安装其他版本office后,调用ppt的com组件会导致弹窗错误:
    “无法将型别 'System.__ComObject' 的 COM 对象转换为接口型别 'Microsoft.Office.Interop.PointPower._Application'。由于发生下列错误,接口 (IID 为 '{{91493440-5A91-11CF-8700-00AA0060263B}') 之 COM 组件上的 QueryInterface 呼叫失败而导致作业失败: 链接库未登录。 (发生例外状况于 HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))。"}”

        手动解决办法:

      删除注册表ClassesROOTTypeLib{91493440-5A91-11CF-8700-00AA0060263B}项下的2.b即可。

      由于本人公司需要,写了一个修改的小工具,需要的可以代码拿去,也可以做一些修改。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Win32;
    
    namespace office2013辅助卸载工具
    {
        class Program
        {
            static void Main(string[] args)
            {
                if (!IsRegeditItemExist())
                {
                    RegistryKey key = Registry.ClassesRoot;
                    key.DeleteSubKeyTree("TypeLib\{91493440-5A91-11CF-8700-00AA0060263B}\2.b", true); //该方法无返回值,直接调用即可
                    key.Close();
                    Console.WriteLine("Office2013残留项已经清除!");
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("不需要清除,请谨慎操作!");
                    Console.ReadLine();
                }
                    
            }
    
            //判断注册表PrimaryInterAssemblyName项是否存在
            private static bool IsRegeditItemExist()
            {
                string[] subkeyNames;
                RegistryKey hkcr = Registry.ClassesRoot;
                RegistryKey officeKey = hkcr.OpenSubKey("TypeLib\{91493440-5A91-11CF-8700-00AA0060263B}\2.b");
                //RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);  
                subkeyNames = officeKey.GetValueNames();
                //取得该项下所有子项的名称的序列,并传递给预定的数组中  
                foreach (string keyName in subkeyNames)
                //遍历整个数组  
                {
                    if (keyName == "PrimaryInteropAssemblyName")
                    //判断子项的名称  
                    {
                        hkcr.Close();
                        return true;
                    }
                }
                hkcr.Close();
                return false;
            }
        }
    }
    
  • 相关阅读:
    最长回文字符(需要补)
    无重复字符的最长子串
    两数之和——链表
    两个数之和
    android 动画基础绘——帧动画(三)
    android 动画基础绘——view 动画(二)[补]
    android 动画基础绘——view 动画
    全国疫情精准定点动态更新(.net core)
    桶排序
    计数排序
  • 原文地址:https://www.cnblogs.com/xietianjiao/p/5127514.html
Copyright © 2020-2023  润新知