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

时间:2021-05-20 11:47:10

We have made an excel add in that is installed correctly and will only show up when opening Excel from the main icon (or a blank workbook). It will NOT show up on the toolbar when opening any existing saved excel document.

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

I have made sure that when opening an existing document, under file -> options -> add in, it is correctly checked in the COM add ins. For us to use our add in, we have to open up a blank workbook, and drag our existing file to the blank workbook.

我确保在打开现有文档时,在文件 - >选项 - >添加下,它在COM添加项中正确检查。对于我们使用我们的添加,我们必须打开一个空白工作簿,并将我们现有的文件拖到空白工作簿。

Would anyone have any idea why it would only show up in the ribbon on a blank workbook and not on existing .xlsx files?

有谁会知道它为什么只会出现在空白工作簿的功能区而不是现有的.xlsx文件?

I have even ran a test where I open a blank workbook, confirm the add in is on the ribbon, put some text in a cell, save it to my desktop, close it, and then reopen it. It then does NOT show up. This add in was made with VS2010.

我甚至运行了一个测试,我打开一个空白的工作簿,确认添加在功能区上,将一些文本放在一个单元格中,将其保存到我的桌面,关闭它,然后重新打开它。然后它不显示。这个添加是用VS2010完成的。

Here is the code from "ThisAddIn.cs"

这是“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
}

Here is the code from the Ribbon.cs file that we made...all it is doing is populating a few fields and setting up:

以下是我们制作的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);
      }
    }
  }
}

1 个解决方案

#1


1  

Sorry for the late answer, but it is very common problem, so I will answer anyway. I encountered it myself a few times, and it had nothing to do with the code of my addin. The problem was in preview pane in explorer. 我的Excel 2010加入仅在打开空白工作簿时显示。打开现有文档时不会显示When you select your excel file in Explorer, it starts an instance of Excel for preview. And then you open your file in real Excel, some bug in Excel prevents all the addins to load. Your addin won't even start any code, so you cannot do anything from inside of your addin. The only way is not to use preview with excel files. And even worse, after one file is previewed, the Excel process still hangs in memory, so addins won't work until you kill it from taskmanager. This bug is in the excel 2007, 2010, 1013 and maybe even 2016.

对不起,迟到的答案,但这是很常见的问题,所以无论如何我都会回答。我自己几次遇到它,它与我的插件的代码无关。问题出在explorer的预览窗格中。在资源管理器中选择excel文件时,它会启动Excel实例进行预览。然后你在真正的Excel中打开你的文件,Excel中的一些错误会阻止加载所有的插件。您的插件甚至不会启动任何代码,因此您无法在插件内部执行任何操作。唯一的方法是不要使用excel文件预览。更糟糕的是,在预览了一个文件后,Excel进程仍会挂起内存,因此在从taskmanager中删除它之前,addins将无法工作。这个bug出现在excel 2007,2010,1013甚至2016年。

#1


1  

Sorry for the late answer, but it is very common problem, so I will answer anyway. I encountered it myself a few times, and it had nothing to do with the code of my addin. The problem was in preview pane in explorer. 我的Excel 2010加入仅在打开空白工作簿时显示。打开现有文档时不会显示When you select your excel file in Explorer, it starts an instance of Excel for preview. And then you open your file in real Excel, some bug in Excel prevents all the addins to load. Your addin won't even start any code, so you cannot do anything from inside of your addin. The only way is not to use preview with excel files. And even worse, after one file is previewed, the Excel process still hangs in memory, so addins won't work until you kill it from taskmanager. This bug is in the excel 2007, 2010, 1013 and maybe even 2016.

对不起,迟到的答案,但这是很常见的问题,所以无论如何我都会回答。我自己几次遇到它,它与我的插件的代码无关。问题出在explorer的预览窗格中。在资源管理器中选择excel文件时,它会启动Excel实例进行预览。然后你在真正的Excel中打开你的文件,Excel中的一些错误会阻止加载所有的插件。您的插件甚至不会启动任何代码,因此您无法在插件内部执行任何操作。唯一的方法是不要使用excel文件预览。更糟糕的是,在预览了一个文件后,Excel进程仍会挂起内存,因此在从taskmanager中删除它之前,addins将无法工作。这个bug出现在excel 2007,2010,1013甚至2016年。