2

我创建了一个 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(" ");          
        }
    }
}
4

0 回答 0