2015-09-16 87 views
1

我正在開發一個使用VB.NET的Excel加載項。在此加載項中,我創建了一個新的功能區,在此功能區中將出現一個Excel工作簿菜單,並且菜單的每一行都應該具有工作簿工作表的子菜單(正在檢索這些文件名,路徑和表單來自DB)。如何使用VSTO將項目添加到Excel菜單?

我在嘗試將這些工作簿插入爲菜單項時出現問題。我創建了一個DAL來檢索我需要和測試的所有數據,它工作正常,我的問題是添加Workbook列表的每個元素。歡迎任何建議。

Public Class Ribbon1 
    Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load 
     Dim listaWorkbooks As New List(Of Workbook) 
     Dim serviceExecuta As New ServiceExecuta 

     listaWorkbooks = serviceExecuta.BuscaWorkbooks() 

     For Each Workbook In listaWorkbooks 

      Menu1.Items.Add(Workbook.getNome) 
     Next 

    End Sub 
End Class 

回答

0

我用一個按鈕加載工作表中組合框的絲帶...... 同樣的方式,你可以檢查工作簿也是如此。
請參閱如下:

Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button19.Click 
    ComboBox1.Items.Clear() 
    Dim rdi As RibbonDropDownItem 
    Dim i As Integer 
    Dim nm() As String 
    For i = 1 To Globals.ThisAddIn.Application.Sheets.Count 
     ReDim nm(i) 
     nm(i) = Globals.ThisAddIn.Application.Sheets(i).Name 
     rdi = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem() 
     rdi.Label = nm(i) 
     ComboBox1.Items.Add(rdi) 
    Next i 
End Sub 

可能是你可以嘗試這樣的事:

 For i = 1 To Globals.ThisAddIn.Application.Workbooks.Count 
      ReDim nm(i) 
      nm(i) = Globals.ThisAddIn.Application.Workbooks(i).Name 
      rdi = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem() 
      rdi.Label = nm(i) 
      ComboBox1.Items.Add(rdi) 
     Next i 

祝您好運!

相關問題