Exemple #1
0
        private void Application_WorkbookActivate(Workbook Wb)
        {
            // This method is called whenever a workbook comes to the front
            // Does not necessarily need to be a workbook that is persisted on the disk
            var workbook = DataModel.Instance.WorkbookModels.Where(p => ReferenceEquals(p.Workbook, Wb))
                           .FirstOrDefault();

            if (workbook == null)
            {
                workbook = new WorkbookModel(Wb);
                DataModel.Instance.WorkbookModels.Add(workbook);

                DataModel.Instance.CurrentWorkbook = workbook;
                DataModel.Instance.CurrentWorkbook.LoadExtraInformation();

                /// create shared pane
                var SidebarContainer = new SidebarContainer();
                var Sidebar          = CustomTaskPanes.Add(SidebarContainer, "Sidebar");

                SidebarContainer.Sidebar.DataContext = workbook;
                Sidebar.Width = 320;
                TaskPanes.Add(new Tuple <WorkbookModel, string>(workbook, "Sidebar"), Sidebar);

                //add selection changed event handler for ribbon
                Wb.Application.SheetSelectionChange += DataModel.Instance.WorkbookSelectionChangedEventHandler;
            }

            DataModel.Instance.CurrentWorkbook = workbook;
        }
Exemple #2
0
        private void ProceedCustomPaneAttributes()
        {
            CustomPaneAttribute[] paneAttributes = AttributeReflector.GetCustomPaneAttributes(Type);
            foreach (CustomPaneAttribute itemPane in paneAttributes)
            {
                if (null != itemPane)
                {
                    TaskPaneInfo item = TaskPanes.Add(itemPane.PaneType, itemPane.PaneType.Name);
                    item.Title                = itemPane.Title;
                    item.Visible              = itemPane.Visible;
                    item.DockPosition         = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), itemPane.DockPosition.ToString());
                    item.DockPositionRestrict = (Office.Enums.MsoCTPDockPositionRestrict)Enum.Parse(typeof(Office.Enums.MsoCTPDockPositionRestrict), itemPane.DockPositionRestrict.ToString());
                    item.Width                = itemPane.Width;
                    item.Height               = itemPane.Height;
                    item.Arguments            = new object[] { this };

                    if (CallOnCreateTaskPaneInfo(item))
                    {
                        item.VisibleStateChange      += new NetOffice.OfficeApi.CustomTaskPane_VisibleStateChangeEventHandler(AttributePane_VisibleStateChange);
                        item.DockPositionStateChange += new Office.CustomTaskPane_DockPositionStateChangeEventHandler(AttributePane_DockPositionStateChange);
                    }
                    else
                    {
                        TaskPanes.Remove(item);
                    }
                }
            }
        }
Exemple #3
0
 public ThisAddin()
 {
     // we create the taskpane
     TaskPanes.Add(typeof(TwitterPane), "Twitter (powered by Linq2Twitter)");
     TaskPanes[0].DockPosition         = MsoCTPDockPosition.msoCTPDockPositionRight;
     TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
     TaskPanes[0].Width   = 300;
     TaskPanes[0].Visible = true;
 }
Exemple #4
0
 public TestAddin()
 {
     TaskPanes.Add(typeof(SampleControl), "NOTestsMain - C# Word Pane");
     TaskPanes[0].DockPosition         = MsoCTPDockPosition.msoCTPDockPositionRight;
     TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
     TaskPanes[0].Width     = 150;
     TaskPanes[0].Visible   = true;
     TaskPanes[0].Arguments = new object[] { this };
     TaskPanes[0].Arguments = new object[] { this };
     this.OnConnection     += new OnConnectionEventHandler(TestAddin_OnConnection);
 }
Exemple #5
0
        public ThisAddin()
        {
            // we create the taskpane
            TaskPanes.Add(typeof(WikipediaPane), "Wikipedia - NetOffice Sample");
            TaskPanes[0].DockPosition         = MsoCTPDockPosition.msoCTPDockPositionRight;
            TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
            TaskPanes[0].Width   = 520;
            TaskPanes[0].Visible = true;

            this.OnConnection      += new OnConnectionEventHandler(ThisAddin_OnConnection);
            this.OnStartupComplete += new OnStartupCompleteEventHandler(ThisAddin_OnStartupComplete);
        }
Exemple #6
0
 public Addin()
 {
     // we can add our own taskpanes here, if you dont want that then overwrite the CTPFactoryAvailable method
     // show into the SamplePane.cs to see how you can use the NetOffice ITaskPane interface to get more control for Load/Unload and connect the host application
     TaskPanes.Add(typeof(TestPane), "NetOffice Tools - Sample Pane(CS4)");
     TaskPanes[0].DockPosition         = MsoCTPDockPosition.msoCTPDockPositionTop;
     TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
     TaskPanes[0].Height              = 50;
     TaskPanes[0].Visible             = true;
     TaskPanes[0].Arguments           = new object[] { this };
     TaskPanes[0].VisibleStateChange += new Office.CustomTaskPane_VisibleStateChangeEventHandler(TaskPane_VisibleStateChange);
     this.OnStartupComplete          += new OnStartupCompleteEventHandler(Addin_OnStartupComplete);
 }
Exemple #7
0
        /// <summary>
        /// Creates an instance of the class
        /// </summary>
        public ThisAddIn()
        {
            // we create the taskpane
            TaskPanes.Add(typeof(TranslationPane), "Google Translation - NetOffice Local Shared Data Sample");
            TaskPanes[0].DockPosition         = MsoCTPDockPosition.msoCTPDockPositionBottom;
            TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoVertical;
            TaskPanes[0].Height  = 150;
            TaskPanes[0].Visible = true;

            // register some typical addin events
            this.OnConnection    += new OnConnectionEventHandler(ThisAddIn_OnConnection);
            this.OnDisconnection += new OnDisconnectionEventHandler(ThisAddIn_OnDisconnection);
        }
Exemple #8
0
        public Addin()
        {
            // trigger the well known IExtensibility2 methods, this is very similar to VSTO
            this.OnStartupComplete += new OnStartupCompleteEventHandler(Addin_OnStartupComplete);

            // wen can add our own taskpanes here, if you dont want that then overwrite the CTPFactoryAvailable method
            // show into the SamplePane.cs to see how you can use the NetOffice ITaskPane interface to get more control for Load/Unload and connect the host application
            TaskPanes.Add(typeof(SamplePane), "NetOffice Tools - Sample Pane");
            TaskPanes[0].DockPosition         = MsoCTPDockPosition.msoCTPDockPositionRight;
            TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
            TaskPanes[0].Width     = 150;
            TaskPanes[0].Visible   = true;
            TaskPanes[0].Arguments = new object[] { this };
        }
Exemple #9
0
        /// <summary>
        /// creates an instance of the class
        /// </summary>
        public Addin()
        {
            Factory.Settings.ExceptionMessage = "#Error";
            Factory.Console.Name = "CodeCommander";

            this.OnStartupComplete += new OnStartupCompleteEventHandler(Addin_OnStartupComplete);
            this.OnDisconnection   += new OnDisconnectionEventHandler(Addin_OnDisconnection);

            TaskPanes.Add(typeof(UI.DeveloperPane), "Code Commander");
            TaskPanes[0].DockPosition         = MsoCTPDockPosition.msoCTPDockPositionRight;
            TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNone;
            TaskPanes[0].Width               = 320;
            TaskPanes[0].Visible             = true;
            TaskPanes[0].Arguments           = new object[] { this };
            TaskPanes[0].VisibleStateChange += new CustomTaskPane_VisibleStateChangeEventHandler(TaskPane_VisibleStateChange);
        }
Exemple #10
0
        public Addin()
        {
            // Enable shared debug output and send a load message(use NOTools.ConsoleMonitor.exe to observe the shared console output)
            Factory.Console.EnableSharedOutput = true;
            Factory.Console.SendPipeConsoleMessage(null, "Addin has been loaded.");

            // We want observe the current count of open proxies with NOTools.ConsoleMonitor.exe
            Factory.Settings.EnableProxyCountChannel = true;

            // trigger the well known IExtensibility2 methods, this is very similar to VSTO
            this.OnStartupComplete += new OnStartupCompleteEventHandler(Addin_OnStartupComplete);

            // wen can add our own taskpanes here, if you dont want that then overwrite the CTPFactoryAvailable method
            // show into the SamplePane.cs to see how you can use the NetOffice ITaskPane interface to get more control for Load/Unload and connect the host application
            TaskPanes.Add(typeof(SamplePane), "NetOffice Tools - Sample Pane(CS4)");
            TaskPanes[0].DockPosition         = MsoCTPDockPosition.msoCTPDockPositionTop;
            TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
            TaskPanes[0].Height              = 50;
            TaskPanes[0].Visible             = true;
            TaskPanes[0].Arguments           = new object[] { this };
            TaskPanes[0].VisibleStateChange += new Office.CustomTaskPane_VisibleStateChangeEventHandler(TaskPane_VisibleStateChange);
        }
Exemple #11
0
 private void Addin_OnConnection(object app, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
 {
     try
     {
         _outlookApplication = new OutLook.Application(null, app);
         TaskPanes.Add(typeof(TaskPaneContainerControl), "侧边栏标题");
         TaskPanes[0].DockPosition         = MsoCTPDockPosition.msoCTPDockPositionBottom;
         TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
         TaskPanes[0].Height    = 100;
         TaskPanes[0].Visible   = true;
         TaskPanes[0].Arguments = new object[] { this };
         // register add signature after new mail
         var i = _outlookApplication.Inspectors as OutLook.Inspectors;
         if (i != null)
         {
             i.NewInspectorEvent += i_NewInspectorEvent;
         }
     }
     catch (Exception exception)
     {
         // 处理
     }
 }
Exemple #12
0
        /// <summary>
        /// ICustomTaskPaneConsumer implementation
        /// </summary>
        /// <param name="CTPFactoryInst">factory proxy from host application</param>
        public virtual void CTPFactoryAvailable(object CTPFactoryInst)
        {
            try
            {
                if (null == CTPFactoryInst)
                {
                    Factory.Console.WriteLine("Warning: null argument recieved in CTPFactoryAvailable. argument name: CTPFactoryInst");
                    return;
                }

                CustomPaneAttribute paneAttribute = AttributeHelper.GetCustomPaneAttribute(Type);
                if (null != paneAttribute)
                {
                    TaskPaneInfo item = TaskPanes.Add(paneAttribute.PaneType, paneAttribute.PaneType.Name);
                    if (!CallOnCreateTaskPaneInfo(item))
                    {
                        item.Title                = paneAttribute.Title;
                        item.Visible              = paneAttribute.Visible;
                        item.DockPosition         = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), paneAttribute.DockPosition.ToString());
                        item.DockPositionRestrict = (Office.Enums.MsoCTPDockPositionRestrict)Enum.Parse(typeof(Office.Enums.MsoCTPDockPositionRestrict), paneAttribute.DockPositionRestrict.ToString());
                        item.Width                = paneAttribute.Width;
                        item.Height               = paneAttribute.Height;
                        item.Arguments            = new object[] { this };
                    }

                    item.VisibleStateChange      += new NetOffice.OfficeApi.CustomTaskPane_VisibleStateChangeEventHandler(AttributePane_VisibleStateChange);
                    item.DockPositionStateChange += new Office.CustomTaskPane_DockPositionStateChangeEventHandler(AttributePane_DockPositionStateChange);
                }

                TaskPaneFactory = new NetOffice.OfficeApi.ICTPFactory(Factory, null, CTPFactoryInst);
                foreach (TaskPaneInfo item in TaskPanes)
                {
                    string title = item.Title;
                    Office.CustomTaskPane taskPane = TaskPaneFactory.CreateCTP(item.Type.FullName, title) as Office.CustomTaskPane;
                    item.Pane = taskPane;
                    item.AssignEvents();
                    item.IsLoaded = true;

                    switch (taskPane.DockPosition)
                    {
                    case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionLeft:
                    case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionRight:
                        taskPane.Width = item.Width;
                        break;

                    case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionTop:
                    case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionBottom:
                        taskPane.Height = item.Height;
                        break;

                    case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionFloating:
                        item.Width      = paneAttribute.Width;
                        taskPane.Height = item.Height;
                        break;

                    default:
                        break;
                    }

                    ITaskPane pane = taskPane.ContentControl as ITaskPane;
                    if (null != pane)
                    {
                        TaskPaneInstances.Add(pane);
                        object[] argumentArray = new object[0];

                        if (item.Arguments != null)
                        {
                            argumentArray = item.Arguments;
                        }

                        pane.OnConnection(Application, taskPane, argumentArray);
                    }

                    foreach (KeyValuePair <string, object> property in item.ChangedProperties)
                    {
                        if (property.Key == "Title")
                        {
                            continue;
                        }

                        try
                        {
                            if (property.Key == "Width") // avoid to set width in top and bottom align
                            {
                                object outValue = null;
                                item.ChangedProperties.TryGetValue("DockPosition", out outValue);
                                if (null != outValue)
                                {
                                    Office.Enums.MsoCTPDockPosition position = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), outValue.ToString());
                                    if (position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionTop || position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionBottom)
                                    {
                                        continue;
                                    }
                                }
                            }

                            if (property.Key == "Height")   // avoid to set height in left and right align
                            {
                                object outValue = null;
                                item.ChangedProperties.TryGetValue("DockPosition", out outValue);
                                if (null == outValue)
                                {
                                    outValue = Office.Enums.MsoCTPDockPosition.msoCTPDockPositionRight; // NetOffice default position if unset
                                }
                                Office.Enums.MsoCTPDockPosition position = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), outValue.ToString());
                                if (position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionLeft || position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionRight)
                                {
                                    continue;
                                }
                            }

                            taskPane.GetType().InvokeMember(property.Key, BindingFlags.SetProperty, null, taskPane, new object[] { property.Value });
                        }
                        catch
                        {
                            ;
                        }
                    }
                }
            }
            catch (NetRuntimeSystem.Exception exception)
            {
                Factory.Console.WriteException(exception);
                OnError(ErrorMethodKind.CTPFactoryAvailable, exception);
            }
        }