代码 拿上来看看 应该可以的啊 我就用过Visio和Excel一起编程 
代码UP

解决方案 »

  1.   


                    temppath = filepath;//word文档路径
                    exfilepath = open.FileName;//excel文档路径
                         object wordpath =  temppath ;
                string expath = exfilepath;
                                   //打开word文档
                      Word.Application  newApp = new Word.Application();
                    deleteword = newApp.NormalTemplate.Path;
           //控制word关闭事件
                    Word.ApplicationEvents2_Event wdEvents2 = (Word.ApplicationEvents2_Event)newApp;
                    wdEvents2.Quit += new Word.ApplicationEvents2_QuitEventHandler(QuitHandler);                //控制word关闭前事件
                    wdEvents2 = (Word.ApplicationEvents2_Event)newApp;
                    wdEvents2.DocumentBeforeClose += new Word.ApplicationEvents2_DocumentBeforeCloseEventHandler(myWordApp_DocumentBeforeClose);
                   
                    // 打开文档函数
                   doc = newApp.Documents.Open(ref wordpath, ref Unknown, ref readOnly, ref Unknown, ref Unknown,ref Unknown, ref Unknown, ref Unknown,
                     ref Unknown, ref Unknown, ref Unknown,ref Unknown, ref Unknown, ref Unknown,ref Unknown, ref Unknown);
     foreach (Office.CommandBar cb in doc.CommandBars)
                {
                    foreach (Office.CommandBarControl cbc in cb.Controls)
                    {
                        if (cb.Name == "Standard" && (cbc.Caption == "保存(&S)" || cbc.Caption == "打开(&O)..." || cbc.Caption == "新建空白文档(&B)"))
                        {
                            cbc.Enabled = false;
                            cbc.Visible = false;                    }
    if (cb.Name == "Menu Bar" && ((cbc.Caption == "文件(&F)") || (cbc.Caption == "工具(&T)")))
                        {
                            cbc.Enabled = false;
                            cbc.Visible = false;                    }                }            }
                newApp.Visible = true;//显示word文档
                newApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;//禁用word原有弹出对话框
                object missing = System.Reflection.Missing.Value;            //创建自定义菜单条
                Office.CommandBarPopup cmdBarControl1 = null;
                Office.CommandBar commandBar = (Office.CommandBar)newApp.CommandBars.ActiveMenuBar;
                int controlCount1 = commandBar.Controls.Count;
                //添加文件菜单条
                string menuCaption = "文件(&P)";
                cmdBarControl1 = (Office.CommandBarPopup)commandBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, 2, true);
                cmdBarControl1.Tag = "文件";
                cmdBarControl1.Caption = menuCaption;
                commandBar.Visible = true;
     }
    Office.CommandBarButton wordbtn2 = cmdBarControl1.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true) as Office.CommandBarButton;            wordbtn2.Caption = "新建";
                wordbtn2.Tag = "新建";
                wordbtn2.Enabled = true;
                wordbtn2.Style = Office.MsoButtonStyle.msoButtonCaption;
                wordbtn2.FaceId = 0162;
                wordbtn2.Click += new Office._CommandBarButtonEvents_ClickEventHandler(wordbtn2_Click);          //excel文档    
        newexAPP = new Excel.Application();
                                  //excel关闭前事件
                    Excel.AppEvents_WorkbookBeforeCloseEventHandler EventDel_BeforeBookClose;
                    EventDel_BeforeBookClose = new Excel.AppEvents_WorkbookBeforeCloseEventHandler(BeforeBookClose);
                    newexAPP.WorkbookBeforeClose += EventDel_BeforeBookClose;                // 打开excel文档函数 
                    xls = newexAPP.Workbooks.Open(expath, readOnly,Unknown,Unknown, Unknown,Unknown, Unknown, Unknown,
                    Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,Unknown);            //禁用excel文档某些原有菜单按钮
              foreach (Office.CommandBar cb in newexAPP.CommandBars)
                    {
                         foreach (Office.CommandBarControl cbc in cb.Controls)
                        {
                             if (cb.Name == "Standard" && (cbc.Caption == "保存(&S)" || cbc.Caption == "打开" || cbc.Caption == "新建(&N)"))
                            {
                                cbc.Enabled = false;
                                cbc.Visible = false;                        }                         if (cb.Name == "Worksheet Menu Bar" && ((cbc.Caption == "文件(&F)") || (cbc.Caption == "工具(&T)")))
                            {
                                cbc.Enabled = false;
                                cbc.Visible = false;
                            }
                        
                         }
                   
                    }
           
                    newexAPP.DisplayStatusBar = false;
                    newexAPP.Visible = true;
                                  object missing = System.Reflection.Missing.Value;               //创建文件菜单条
                    Office.CommandBarPopup cmdBarControl = null;
                    Office.CommandBar excommandBar = (Office.CommandBar)newexAPP.CommandBars.ActiveMenuBar;
                    int controlCount = excommandBar.Controls.Count;
                    string menuCaption = "文件(&P)";
                    cmdBarControl = (Office.CommandBarPopup)excommandBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, 2, true);
                    cmdBarControl.Tag = "文件";                if (cmdBarControl != null)
                    {
                        cmdBarControl.Caption = menuCaption;
                        
                        //添加excel新建文档按钮
                        Office.CommandBarButton excelbtn4 = cmdBarControl.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true) as Office.CommandBarButton;                    excelbtn4.Caption = "新建";
                        excelbtn4.Tag = "新建";
                        excelbtn4.Enabled = true;
                        excelbtn4.Style = Office.MsoButtonStyle.msoButtonCaption;
                        excelbtn4.FaceId = 0162;
                        excelbtn4.Click += new Office._CommandBarButtonEvents_ClickEventHandler(excelbtn4_Click);
                      
                    
      

  2.   


    不是很清楚,要操作某文档,是否应该先active这个。
      

  3.   

        是啊,如果是涉及的只是word文档的话,可以doc.active,可是excel文档一打开,这个doc.active好像不起作用了