当前位置: 首页>>代码示例>>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;未经允许,请勿转载。