我们制作了一个正确安装的 excel 插件,仅在从主图标(或空白工作簿)打开 Excel 时才会显示。打开任何现有保存的 Excel 文档时,它不会显示在工具栏上。
我已确保在打开现有文档时,在文件 -> 选项 -> 插件下,它已在 COM 插件中正确检查。为了使用我们的插件,我们必须打开一个空白工作簿,并将我们现有的文件拖到空白工作簿中。
有谁知道为什么它只会出现在空白工作簿的功能区中而不是现有的 .xlsx 文件中?
我什至运行了一个测试,我打开一个空白工作簿,确认加载项在功能区上,在单元格中放入一些文本,将其保存到我的桌面,关闭它,然后重新打开它。然后它不会出现。这个插件是用 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);
}
}
}
}