我创建了一个Excel功能区。它包含一个下拉列表,其中打开工作簿时将填充工作簿中所有工作表的名称。现在我想从下拉列表中选择多个工作表,并仅对这些工作表执行某些操作。有没有办法从下拉列表中选择多个选项。 Checkedlistbox控件不适用于Excel功能区。这是我知道处理这种情况的唯一方法。任何帮助都会很棒。提前致谢。这是我的代码:
namespace Ribbon {
public partial class ExcelRibbon {
List<string> Sheets = new List<string>();
private void ExcelRibbon_Load(object sender, RibbonUIEventArgs e) {
Globals.ThisAddIn.Application.WorkbookOpen += new Excel.AppEvents_WorkbookOpenEventHandler(Application_WorkbookOpen);
}
void Application_WorkbookOpen(Excel.Workbook Wb) {
SheetsCollection.Items.Clear();
for (int i = 1; i < Globals.ThisAddIn.Application.Sheets.Count; i++) {
RibbonDropDownItem item = this.Factory.CreateRibbonDropDownItem();
item.Label = Globals.ThisAddIn.Application.Sheets[i].Name;
SheetsCollection.Items.Add(item);
}
}
private void SheetsCollection_SelectionChanged(object sender, RibbonControlEventArgs e) {
SheetsCollection.SelectedItem.Label = SheetsCollection.SelectedItem.Label + " *";
if(SheetsCollection.SelectedItem.Label.EndsWith("*"))
Sheets.Add(SheetsCollection.SelectedItem.Label.Substring(0,SheetsCollection.SelectedItem.Label.LastIndexOf(" ");
}
}
}