SplitButton question on converting excel addin to use addin express

Add-in Express™ Support Service
That's what is more important than anything else

SplitButton question on converting excel addin to use addin express
cant reproduce split button behavior from original excel addin Ribbon 
Martin Tremblay




Posts: 6
Joined: 2021-10-20
Hi
I am porting an existing Excel addin to use Addin Express, and i am unable to reproduce a simple behavior of a SplitButton from the original addin. In the original addin there is a SPlit Button defined with along with the following items:


<splitButton id="splitbutton1" >
            <menu id="Menu1">
              <menuSeparator id="mensep1" title="Standard Reports"/>
              <button id="YesterdayID" onAction="Yesterday_Click" label="Yesterday" imageMso="DatabaseAccessBackEnd" showImage="true" />
              <button id="PreviousWeekID" onAction="PreviousWeek_Click" label=" Last Week" imageMso="DatabaseAccessBackEnd" showImage="true" />
              <button id="PreviousMonthID" onAction="PreviousMonth_Click"  label=" Last Month" imageMso="DatabaseAccessBackEnd" showImage="true" />
            </menu>
          </splitButton>


and when you start excel yopu can see that the default item showned is the Button with the Caption being "Yesterday",

and there is noting in code that seem to do that, and also nothing in the ribbon.xml is set that could do that.



I am trying to do the same rebuilding the Ribbon with Addin express.

thanks in advance for any help
Posted 23 Feb, 2022 08:55:18 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Martin,

Martin Tremblay writes:
when you start excel yopu can see that the default item showned is the Button with the Caption being "Yesterday"


How this should work?

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Feb, 2022 09:30:08 Top
Martin Tremblay




Posts: 6
Joined: 2021-10-20
Hello Andrei

i tried inserting images in my post, but it seems like only images from a url can be inserted in forum posts?
please let me know how i cna attach images or files to forum post.
Posted 23 Feb, 2022 10:32:58 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Martin,

You can send the images to the support email address; see {Add-in Express installation folder}\readme.txt.

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 24 Feb, 2022 10:26:38 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Martin,

Thank you for the explanation and details that you sent to us.

You can intercept the OnRibbonBeforeLoad event - see the add-in module - and get the XML that Add-in Express generates. I use this construct: Clipboard.SetText(e.Xml). Note that sometimes it fires an exception: ignore it and restart the host application.

Comparing two Ribbon XMLs showed that Add-in Express adds an extra <button> tag.

Your example:
<splitButton ...
<menu ...
<menuSeparator ...
<button id="YesterdayID" ...


Add-in Express:
<splitButton id="splitButtonId" ...
<button id="splitButtonId_wrapped" ...
<menu ...
<menuSeparator ...
<button id="{some ID here}" ...


You can achieve your goal if you delete that "wrapped" button tag from the XML.

NOTE: All code below was originally written in C#. Then I've used an online converter to get the VB code; I haven't tested it.
NOTE2: You must replace the IDs mentioned below with your actual IDs.

Below is a method that replaces strings in the Ribbon XML. To delete that tag, call this method in the OnRibbonBeforeLoad event as follows:


    findXML = "<button getDescription=""getDescription_Callback"" getLabel=""getLabel_Callback"" getScreentip=""getScreenTip_Callback"" getShowImage=""getShowImage_Callback"" getSupertip=""getSuperTip_Callback"" id=""adxRibbonSplitButton_63fb957f14e44c2c84d10445d542d796_wrapped"" onAction=""onActionCommon_Callback"" />"
    replaceXML = ""
    e.Xml = UpdateXml(e.Xml, adxRibbonSplitButton1.Id & "_wrapped", findXML, replaceXML)



Private Function UpdateXml(ByVal ribbonXML As String, ByVal id As String, ByVal find As String, ByVal replace As String) As String
    Dim lines As String() = ribbonXML.Split(New String() {Environment.NewLine}, StringSplitOptions.None)

    For i As Integer = 0 To lines.Length - 1

        If lines(i).Contains(id) Then
            lines(i) = lines(i).Replace(find, replace)
            Exit For
        End If
    Next

    Dim result As String = String.Empty

    For i As Integer = 0 To lines.Length - 1
        result += lines(i) & Environment.NewLine
    Next

    Return result
End Function


Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 01 Mar, 2022 07:19:02 Top
Martin Tremblay




Posts: 6
Joined: 2021-10-20
Hello Andrei

thanks for the reply, and sorry for the delay responding.
I will try what you posted just as a test to see if removing that extra tag will change the SplitButton to show the "Yesterday: button by default, but now the question i would have is why Add-in Express is adding that Extra Button tag?

I am not sure anyway on why the SplitButton shows the "yesterday" Button by default in our original vsto project, as i cannot find any properties set to do that, but was just curious.

thanks again
Martin
Posted 03 Mar, 2022 07:30:17 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Martin,

At https://docs.microsoft.com/en-us/openspecs/office_standards/ms-customui2/4ed1a596-1368-4112-9adf-6f804db37ec0, they provide the Ribbon schema fragment for the CT_SplitButtonRegular type. That fragment shows that the button (or toggle button) is optional. We can't remember why we chose to make it obligatory; there's a dim remembrance of an issue in some Office version (2007 or 2010) that might influence this decision.

If this poses an issue, we could consider adding a property to solve this.

Martin Tremblay writes:
I am not sure anyway on why the SplitButton shows the "yesterday" Button by default in our original vsto project, as i cannot find any properties set to do that


This behavior isn't described.

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 04 Mar, 2022 06:29:09 Top