admin管理员组

文章数量:1583042

 

using Microsoft.Office.Interop.Excel;       

 

 

打开Excel

        private const string Microsoft_EXCEL_PROG_ID = "Excel.Application";
        private const string WPS_EXCEL_PROG_ID = "KET.Application";      

              if (Type.GetTypeFromProgID(ExcelSoftName) is Type excelType)
                    {
                        try
                        {
                            app = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject(ExcelSoftName);
                        }
                        catch
                        {
                            // Excel is not running.
                            app = (Application)Activator.CreateInstance(excelType);
   
                        }

判断 打开的是 wps 还是 微软 office

 

public bool IsWPSApp()
        {
            //Path    "C:\\Users\\infodator\\AppData\\Local\\Kingsoft\\WPS Office\\11.1.0.9662\\office6"  System.String 慢
            //StartupPath "C:/Users/infodator/AppData/Local/Kingsoft/WPS Office/11.1.0.9662/office6/startup"  System.String 慢
            //TemplatesPath   "C:/Users/infodator/AppData/Local/Kingsoft/WPS Office/11.1.0.9662/office6/mui/zh_CN/templates"  System.String  快
            //LibraryPath "C:/Users/infodator/AppData/Local/Kingsoft/WPS Office/11.1.0.9662/office6/library"  System.String 快

            //ExcelBot.Shared.App.Path    "C:\\Program Files\\Microsoft Office\\Root\\Office16"   string 慢
            //ExcelBot.Shared.App.StartupPath "C:\\Users\\infodator\\AppData\\Roaming\\Microsoft\\Excel\\XLSTART" string 慢
            //ExcelBot.Shared.App.TemplatesPath   "C:\\Users\\infodator\\AppData\\Roaming\\Microsoft\\Templates\\"    string 快
            //ExcelBot.Shared.App.LibraryPath "C:\\Program Files\\Microsoft Office\\Root\\Office16\\LIBRARY"  string 快

            return ExcelBot.Shared.App.TemplatesPath.ToLower().Contains("wps");
        }

 

本文标签: 的是微软InteropMicrosoftoffice