This project has moved and is read-only. For the latest updates, please go here.
/*
   customize classic UI in Excel
   taken from Example09.cs
*/

private void Example09Main()
{
   Office.CommandBar commandBar;
   Office.CommandBarButton commandBarBtn;
 
   // start excel and turn off msg boxes
   _excelApplication = new Excel.Application();
   _excelApplication.DisplayAlerts = false;
         
   // add a new workbook
   Excel.Workbook workBook = _excelApplication.Workbooks.Add();
                        
   // add a commandbar popup
   Office.CommandBarPopup  commandBarPopup = (Office.CommandBarPopup) _
_excelApplication.CommandBars["Worksheet Menu Bar"].Controls.Add( _
MsoControlType.msoControlPopup); commandBarPopup.Caption = "commandBarPopup"; #region few words, how to access the picture /* you can see we use an own icon via .PasteFace() is not possible from outside process boundaries to use the PictureProperty directly the reason for is IPictureDisp: http://support.microsoft.com/kb/286460/de its not important is early or late binding or managed or unmanaged,
the behaviour is always the same For example, a COMAddin running as InProcServer can access the Picture Property */
#endregion // add a button to the popup commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add( _
MsoControlType.msoControlButton); commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption; commandBarBtn.Caption = "commandBarButton"; Clipboard.SetDataObject(this.Icon.ToBitmap()); commandBarBtn.PasteFace(); commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler( _
commandBarBtn_Click); // add a new toolbar commandBar = _excelApplication.CommandBars.Add("MyCommandBar", _
MsoBarPosition.msoBarTop, false, true); commandBar.Visible = true; // add a button to the toolbar commandBarBtn = (Office.CommandBarButton)commandBar.Controls.Add( _
MsoControlType.msoControlButton); commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption; commandBarBtn.Caption = "commandBarButton"; commandBarBtn.FaceId = 3; commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler( _
commandBarBtn_Click); // add a dropdown box to the toolbar commandBarPopup = (Office.CommandBarPopup)commandBar.Controls.Add( _
MsoControlType.msoControlPopup); commandBarPopup.Caption = "commandBarPopup"; // add a button to the popup, we use an own icon for the button commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add( _
MsoControlType.msoControlButton); commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption; commandBarBtn.Caption = "commandBarButton"; Clipboard.SetDataObject(this.Icon.ToBitmap()); commandBarBtn.PasteFace(); commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler( _
commandBarBtn_Click); add a commandbar popup commandBarPopup = (Office.CommandBarPopup) _
_excelApplication.CommandBars["Cell"].Controls.Add(MsoControlType.msoControlPopup); commandBarPopup.Caption = "commandBarPopup"; // add a button to the popup commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add( _
MsoControlType.msoControlButton); commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption; commandBarBtn.Caption = "commandBarButton"; commandBarBtn.FaceId = 9; commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler( _
commandBarBtn_Click); // make visible _excelApplication.Visible = true; }

Last edited May 14, 2012 at 6:10 AM by SebastianDotNet, version 34

Comments

No comments yet.