我的Excel 2010添加仅在打开空白工作簿时显示。 打开现有文档时不会显示

我们已经做了一个Excel的补充,安装正确,只会显示从主图标(或空白工作簿)打开Excel时。 打开任何现有的保存的Excel文档时,它不会显示在工具栏上。

我已经确定,当打开一个现有的文档,在文件 – >选项 – >添加,它是正确的在COM添join选中。 对于我们使用我们的join,我们必须打开一个空白的工作簿,并拖动我们现有的文件到空白的工作簿。

任何人都不知道为什么它只会出现在空白工作簿的function区而不是现有的.xlsx文件?

我甚至在打开一个空白工作簿的时候运行了一个testing,确认添加的function是在function区上,把一些文本放在一个单元格中,保存到桌面上,closures它,然后重新打开。 然后它不显示。 这个添加是用VS2010做的。

这是来自“ThisAddIn.cs”的代码

public partial class ThisAddIn { private void ThisAddIn_Startup(object sender, System.EventArgs e) { } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { } #region VSTO generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion } 

这里是我们所做的Ribbon.cs文件的代码…它所做的只是填充一些字段并设置:

 private void MyRibbon_Load(object sender, RibbonUIEventArgs e) { Excel._Workbook activeWorkbook = (Excel._Workbook)Globals.ThisAddIn.Application.ActiveWorkbook; if (activeWorkbook.Path == "") { string pathMyDocuments = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); this.editBox1.Text = pathMyDocuments; } else { this.editBox1.Text = activeWorkbook.Path; this.fileBox.Text = "Converted_" + activeWorkbook.Name; } this.folderBrowserDialog1.RootFolder = System.Environment.SpecialFolder.MyComputer; this.folderBrowserDialog1.ShowNewFolderButton = true; //populate the dropdown box with spreadsheet templates using (SqlConnection conn = new SqlConnection("<removed for stack overflow>")) { using (SqlCommand command = new SqlCommand("<sql command text removed for SO", conn)) { command.CommandType = CommandType.Text; conn.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { RibbonDropDownItem item = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem(); item.Label = reader["MasterSpreadsheetName"].ToString(); ddlSpreadsheetTemplate.Items.Add(item); } } } } 

对不起,迟到的答案,但这是非常普遍的问题,所以我会回答。 我自己也遇到了几次,和我的插件代码没有任何关系。 问题出在Explorer中的预览窗格中。 在这里输入图像说明 当您在资源pipe理器中select您的Excel文件时,它会启动一个Excel实例进行预览。 然后你打开你的文件在真正的Excel中,Excel中的一些错误,防止所有的插件加载。 你的插件甚至不会启动任何代码,所以你不能从你的插件里面做任何事情。 唯一的方法是不使用excel文件预览。 更糟糕的是,在预览一个文件后,Excel进程仍然会挂在内存中,所以只有从taskmanager中删除它,插件才能工作。 这个bug是在2007年,2010年,1013年,甚至2016年。