當前位置: 首頁>>代碼示例>>C#>>正文


C# NetOffice.COMObject類代碼示例

本文整理匯總了C#中NetOffice.COMObject的典型用法代碼示例。如果您正苦於以下問題:C# COMObject類的具體用法?C# COMObject怎麽用?C# COMObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


COMObject類屬於NetOffice命名空間,在下文中一共展示了COMObject類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DoTest

        public TestResult DoTest()
        {
            Excel.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new NetOffice.ExcelApi.Application();
                application.Visible = true;
                application.DisplayAlerts = false;
                application.Workbooks.Add();
                Excel.Worksheet sheet = application.Workbooks[1].Sheets[1] as Excel.Worksheet;

                Office.COMAddIn addin = (from a in application.COMAddIns where a.ProgId == "ExcelAddinCSharp.TestAddin" select a).FirstOrDefault();
                if(null == addin)
                    return new TestResult(false, DateTime.Now.Subtract(startTime), "COMAddin ExcelAddinCSharp.TestAddin not found.", null, "");

                bool ribbonIsOkay = false;
                bool taskPaneIsOkay = false;
                if (null != addin.Object)
                { 
                    COMObject addinProxy = new COMObject(null, addin.Object);
                    ribbonIsOkay = (bool)Invoker.PropertyGet(addinProxy, "RibbonUIPassed");
                    taskPaneIsOkay = (bool)Invoker.PropertyGet(addinProxy, "TaskPanePassed");
                    addinProxy.Dispose();
                }

                if( ribbonIsOkay && taskPaneIsOkay)
                    return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
                else
                    return new TestResult(false, DateTime.Now.Subtract(startTime), string.Format("Ribbon:{0} TaskPane:{1}", ribbonIsOkay, taskPaneIsOkay), null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
開發者ID:vnkolt,項目名稱:NetOffice,代碼行數:44,代碼來源:Test09.cs

示例2: OnConnection

        public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
        {
            try
            {
                _application = Core.Default.CreateObjectFromComProxy(null, Application);

                /*
                * _application is stored as COMObject the common base type for all reference types in NetOffice
                * because this addin is loaded in different office application.
                * 
                * with the CreateObjectFromComProxy method the _application instance is created as corresponding wrapper based on the com proxy type
                */

                if (_application is Excel.Application)
                   _hostApplicationName = "Excel";
                else if (_application is Word.Application)
                   _hostApplicationName = "Word";
                else if (_application is Outlook.Application)
                   _hostApplicationName = "Outlook";
                else if (_application is PowerPoint.Application)
                   _hostApplicationName = "PowerPoint";
                else if (_application is Access.Application)
                   _hostApplicationName = "Access";
            }
            catch (Exception exception)
            {
                if(_hostApplicationName != null)
                    OfficeRegistry.LogErrorMessage(_hostApplicationName, _progId, "Error occured in OnConnection. ", exception);
            }
        }
開發者ID:swatt6400,項目名稱:NetOffice,代碼行數:30,代碼來源:Addin.cs

示例3: COMObject

        public COMObject(COMObject replacedObject)
        {
            Factory.CheckInitialize();

            // copy proxy
            _underlyingObject = replacedObject.UnderlyingObject;
            _parentObject = replacedObject.ParentObject;
            _instanceType = replacedObject.InstanceType;

            // copy childs
            foreach (COMObject item in replacedObject.ListChildObjects)
                AddChildObject(item);

            // remove old object from parent chain
            if (!Object.ReferenceEquals(replacedObject.ParentObject, null))
            {
                COMObject parentObject = replacedObject.ParentObject;
                parentObject.RemoveChildObject(replacedObject);

                // add himself as child to parent object
                parentObject.AddChildObject(this);
            }

            Factory.RemoveObjectFromList(replacedObject);
            Factory.AddObjectToList(this);
        }
開發者ID:vnkolt,項目名稱:NetOffice,代碼行數:26,代碼來源:COMObject.cs

示例4: COMObject

        public COMObject(Core factory, COMObject replacedObject)
        {
            // copy current factory info or set default
            if (null == factory)
                factory = Core.Default;
            Factory = factory;

            // copy proxy
            _underlyingObject = replacedObject.UnderlyingObject;
            _parentObject = replacedObject.ParentObject;
            _instanceType = replacedObject.InstanceType;

            // copy childs
            foreach (COMObject item in replacedObject.ListChildObjects)
                AddChildObject(item);

            // remove old object from parent chain
            if (!Object.ReferenceEquals(replacedObject.ParentObject, null))
            {
                COMObject parentObject = replacedObject.ParentObject;
                parentObject.RemoveChildObject(replacedObject);

                // add himself as child to parent object
                parentObject.AddChildObject(this);
            }

            Factory.RemoveObjectFromList(replacedObject);
            Factory.AddObjectToList(this);
        }
開發者ID:netintellect,項目名稱:NetOffice,代碼行數:29,代碼來源:COMObject.cs

示例5: OnConnection

        // ITaskpane Member

        public void OnConnection(COMObject application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments)
        {
            ParentPane = parentPane;
            LastParentPaneVisible = parentPane.Visible;
            commandPane1.OnConnection(application, parentPane, customArguments);
            propertyPane1.OnConnection(application, parentPane, customArguments);
            infoPane1.OnConnection(application, parentPane, customArguments);
        }
開發者ID:netintellect,項目名稱:NetOffice,代碼行數:10,代碼來源:DeveloperPane.cs

示例6: OnConnection

 public void OnConnection(COMObject application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments)
 {
     ApplicationHandler = new OfficeApplicationManager(application);
     AvailableProxy[] proxies = ApplicationHandler.GetAvailableProxies();
     if (proxies.Length > 0)
     {
         comboBoxTarget.DataSource = proxies;
         comboBoxTarget.SelectedIndex = 0;
     }
 }
開發者ID:netintellect,項目名稱:NetOffice,代碼行數:10,代碼來源:PropertyPane.cs

示例7: GetProxyEnumeratorAsProperty

 private IEnumerator GetProxyEnumeratorAsProperty(COMObject comObject)
 {
     object enumProxy = Invoker.Default.PropertyGet(comObject, "_NewEnum");
     COMObject enumerator = new COMObject(Core.Default, comObject, enumProxy, true);
     Invoker.Default.MethodWithoutSafeMode(enumerator, "Reset", null);
     bool isMoveNextTrue = (bool)Invoker.Default.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
     while (true == isMoveNextTrue)
     {
         object itemProxy = Invoker.Default.PropertyGetWithoutSafeMode(enumerator, "Current", null);
         COMObject returnClass = new COMObject(enumerator, itemProxy);
         isMoveNextTrue = (bool)Invoker.Default.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
         yield return returnClass;
     }
 }
開發者ID:netintellect,項目名稱:NetOffice,代碼行數:14,代碼來源:CommandBarsWrapper.cs

示例8: GetScalarEnumeratorAsProperty

 /// <summary>
 /// returns enumerator with scalar variables
 /// </summary>
 /// <param name="comObject"></param>
 /// <returns></returns>
 public static IEnumerator GetScalarEnumeratorAsProperty(COMObject comObject)
 {
     Factory.CheckInitialize();
     object enumProxy = Invoker.PropertyGet(comObject, "_NewEnum");
     COMObject enumerator = new COMObject(comObject, enumProxy, true);
     Invoker.MethodWithoutSafeMode(enumerator, "Reset", null);
     bool isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
     while (true == isMoveNextTrue)
     {
         object item = Invoker.PropertyGetWithoutSafeMode(enumerator, "Current", null);
         isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
         yield return item;
     }
 }
開發者ID:vnkolt,項目名稱:NetOffice,代碼行數:19,代碼來源:Utils.cs

示例9: GetProxyEnumeratorAsMethod

 /// <summary>
 /// returns enumerator with com proxies
 /// </summary>
 /// <param name="comObject"></param>
 /// <returns></returns>
 public static IEnumerator GetProxyEnumeratorAsMethod(COMObject comObject)
 {
     Factory.CheckInitialize();
     object enumProxy = Invoker.MethodReturn(comObject, "_NewEnum");
     COMObject enumerator = new COMObject(comObject, enumProxy, true);
     Invoker.MethodWithoutSafeMode(enumerator, "Reset", null);
     bool isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
     while (true == isMoveNextTrue)
     {
         object itemProxy = Invoker.PropertyGetWithoutSafeMode(enumerator, "Current", null);
         COMObject returnClass = Factory.CreateObjectFromComProxy(enumerator, itemProxy);
         isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
         yield return returnClass;
     }
 }
開發者ID:vnkolt,項目名稱:NetOffice,代碼行數:20,代碼來源:Utils.cs

示例10: MethodWithoutSafeMode

        public static void MethodWithoutSafeMode(COMObject comObject, string name, object[] paramsArray)
        {
            try
            {
                if (comObject.IsDisposed)
                    throw new InvalidComObjectException();

                comObject.InstanceType.InvokeMember(name, BindingFlags.InvokeMethod | BindingFlags.GetProperty, null, comObject.UnderlyingObject, paramsArray, Settings.ThreadCulture);
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw new System.Runtime.InteropServices.COMException(GetExceptionMessage(throwedException), throwedException);
            }
        }
開發者ID:vnkolt,項目名稱:NetOffice,代碼行數:15,代碼來源:Invoker.cs

示例11: Method

        /// <summary>
        /// perform method as latebind call with parameters
        /// </summary>
        /// <param name="comObject">target object</param>
        /// <param name="name">name of method</param>
        /// <param name="paramsArray">array with parameters</param>
        public static void Method(COMObject comObject, string name, object[] paramsArray)
        {
            try
            {
                if(comObject.IsDisposed)
                    throw new InvalidComObjectException();

                if( (Settings.EnableSafeMode) && (!comObject.EntityIsAvailable(name,SupportEntityType.Method)))
                    throw new EntityNotSupportedException(string.Format("Method {0} is not available.", name));

                comObject.InstanceType.InvokeMember(name, BindingFlags.InvokeMethod | BindingFlags.GetProperty, null, comObject.UnderlyingObject, paramsArray, Settings.ThreadCulture);
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw new System.Runtime.InteropServices.COMException(GetExceptionMessage(throwedException), throwedException);
            }
        }
開發者ID:vnkolt,項目名稱:NetOffice,代碼行數:24,代碼來源:Invoker.cs

示例12: DoTest

        public TestResult DoTest()
        {
            Excel.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new NetOffice.ExcelApi.Application();
                application.Visible = true;
                application.DisplayAlerts = false;
                application.Workbooks.Add();
                Excel.Worksheet sheet = application.Workbooks[1].Sheets[1] as Excel.Worksheet;

                Office.COMAddIn addin = (from a in application.COMAddIns where a.ProgId == "NOTestsMain.ExcelTestAddinCSharp" select a).FirstOrDefault();
                if (null == addin || null == addin.Object)
                    return new TestResult(false, DateTime.Now.Subtract(startTime), "NOTestsMain.ExcelTestAddinCSharp or addin.Object not found.", null, "");
                	
                bool addinStatusOkay = false;
                string errorDescription = string.Empty;
                if (null != addin.Object)
                { 
                    COMObject addinProxy = new COMObject(addin.Object);
                    addinStatusOkay = (bool)Invoker.Default.PropertyGet(addinProxy, "StatusOkay");
                    errorDescription = (string)Invoker.Default.PropertyGet(addinProxy, "StatusDescription");
                    addinProxy.Dispose();
                }

                if (addinStatusOkay)
                    return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
                else
                    return new TestResult(false, DateTime.Now.Subtract(startTime), string.Format("NOTestsMain.ExcelTestAddinCSharp Addin Status {0}", errorDescription), null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
開發者ID:netintellect,項目名稱:NetOffice,代碼行數:44,代碼來源:Test09.cs

示例13: DoTest

        public TestResult DoTest()
        {
            Word.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new Word.Application();
                application.Visible = true;
                application.DisplayAlerts = Word.Enums.WdAlertLevel.wdAlertsNone;
                application.Documents.Add();

                Office.COMAddIn addin = (from a in application.COMAddIns where a.ProgId == "NOTestsMain.WordTestAddinCSharp" select a).FirstOrDefault();
                if (null == addin || null == addin.Object)
                    return new TestResult(false, DateTime.Now.Subtract(startTime), "NOTestsMain.WordTestAddinCSharp or addin.Object not found.", null, "");

                bool addinStatusOkay = false;
                string errorDescription = string.Empty;
                if (null != addin.Object)
                {
                    COMObject addinProxy = new COMObject(addin.Object);
                    addinStatusOkay = (bool)Invoker.Default.PropertyGet(addinProxy, "StatusOkay");
                    errorDescription = (string)Invoker.Default.PropertyGet(addinProxy, "StatusDescription");
                    addinProxy.Dispose();
                }

                if (addinStatusOkay)
                    return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
                else
                    return new TestResult(false, DateTime.Now.Subtract(startTime), string.Format("NOTestsMain.WordTestAddinCSharp Addin Status {0}", errorDescription), null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit(WdSaveOptions.wdDoNotSaveChanges);
                    application.Dispose();
                }
            }
        }
開發者ID:swatt6400,項目名稱:NetOffice,代碼行數:43,代碼來源:Test09.cs

示例14: GetProxyEnumeratorAsProperty

        /// <summary>
        /// Returns an enumerator with com proxies
        /// </summary>
        /// <param name="comObject">COMObject instance as any</param>
        /// <returns>IEnumerator instance</returns>
        public static IEnumerator GetProxyEnumeratorAsProperty(COMObject comObject)
        {
            if (null == comObject)
                throw new ArgumentNullException("comObject");

            lock (_lockUtils)
            {
                comObject.Factory.CheckInitialize();
                object enumProxy = comObject.Factory.Invoker.PropertyGet(comObject, "_NewEnum");
                COMObject enumerator = new COMObject(comObject.Factory, comObject, enumProxy, true);
                comObject.Factory.Invoker.MethodWithoutSafeMode(enumerator, "Reset", null);
                bool isMoveNextTrue = (bool)comObject.Factory.Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
                while (true == isMoveNextTrue)
                {
                    object itemProxy = comObject.Factory.Invoker.PropertyGetWithoutSafeMode(enumerator, "Current", null);
                    COMObject returnClass = comObject.Factory.CreateObjectFromComProxy(enumerator, itemProxy);
                    yield return returnClass;
                    isMoveNextTrue = (bool)comObject.Factory.Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
                }
            }
        }
開發者ID:netoffice,項目名稱:NetOffice,代碼行數:26,代碼來源:Utils.cs

示例15: EnumConnectionPoint

        /// <summary>
        /// try to find connection point by EnumConnectionPoints
        /// </summary>
        /// <param name="comInstance"></param>
        /// <param name="connectionPointContainer"></param>
        /// <param name="point"></param>
        /// <param name="sinkIds"></param>
        /// <returns></returns>
        private static string EnumConnectionPoint(COMObject comInstance, IConnectionPointContainer connectionPointContainer, ref IConnectionPoint point, params string[] sinkIds)
        {
            IConnectionPoint[] points = new IConnectionPoint[1];
            IEnumConnectionPoints enumPoints = null;
            try
            {
                connectionPointContainer.EnumConnectionPoints(out enumPoints);
                while (enumPoints.Next(1, points, IntPtr.Zero) == 0) // S_OK = 0 , S_FALSE = 1
                {
                    if (null == points[0])
                        break;

                    Guid interfaceGuid;
                    points[0].GetConnectionInterface(out interfaceGuid);

                    for (int i = sinkIds.Length; i > 0; i--)
                    {
                        string id = interfaceGuid.ToString().Replace("{", "").Replace("}", "");
                        if (true == sinkIds[i - 1].Equals(id, StringComparison.InvariantCultureIgnoreCase))
                        {
                            Marshal.ReleaseComObject(enumPoints);
                            enumPoints = null;
                            point = points[0];
                            return id;
                        }
                    }
                }
                return null;
            }
            catch (Exception throwedException)
            {
                comInstance.Console.WriteException(throwedException);
                return null;
            }
            finally
            {
                if (null != enumPoints)
                    Marshal.ReleaseComObject(enumPoints);
            }
        }
開發者ID:swatt6400,項目名稱:NetOffice,代碼行數:48,代碼來源:SinkHelper.cs


注:本文中的NetOffice.COMObject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。