我正在尝试用RibbonX API为我的Excel插件设置一个透明图标。这是我的XML:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" loadImage="gui_LoadImage">
<ribbon>
<tabs>
<tab id="CBtab" label="2019CBMaster">
<group id="visualizationGroup" label="Visualization">
<button id="btnHistogram" label ="Press here" enabled="true" screentip="Press and see how magic happens" image="icn_btnHistogram.jpg" size="large"/>
</group>
<group id="NewGroup" label="2019NewGroup" >
<box id="bxBo">
<button id="btnNew" label="Press" image="icn_btnHisto.jpg" size="large"/>
<menu id="mnMenu" image="btn_img_random.jpg">
</menu>
</box>
</group>
</tab>
</tabs>
</ribbon>
</customUI>这是设置图片的子部分:为了测试目的,它忽略了xml参数,只是加载了一个“固定”图片:
Sub gui_LoadImage(ImageName As String, ByRef Image)
Set Image = stdole.LoadPicture("C:\Office 2010 Developer Resources\icons\gg.ico")
End Sub我将gg.ico保存在GIMP中,作为24 bpp和1位alpha ico文件。我也尝试过外部ico-s,但它们也没有显示出来。
正如您从上面了解到的,图标的显示并不像它们完全透明一样。
你能帮忙吗?
另外,这个RibbonX API仍然支持吗?我想知道,因为我在做一件非常基本的事情时遇到了困难,而且几乎找不到任何文档。如果不是,开发带有可定制带的Excel外接程序的现代框架是什么?
谢谢。
发布于 2019-06-08 17:17:31
自定义条带UI图标可以是透明的。我相信它们一定是.png文件。下面是UI条带图标设置的详细信息,其中包括透明的背景。
https://learn.microsoft.com/en-us/office/dev/add-ins/design/add-in-icons
修订
在自定义UI编辑器中,您可以导入图像文件,然后在XML代码中引用文件名。文件类型和图像本身是否有透明的背景是我所认为的决定它是否透明地出现在丝带上。这就是XML的样子。<button id="customButton1" label="Label 1" size="large" onAction="Macro1" image="picture1" />
在查看XML代码时,我看到图像中包含了文件扩展名。我不包括文件扩展名与我的自定义图像图标。在我链接的自定义UI编辑器中,您可以添加导入图像文件,该文件出现在侧窗格中,然后只引用XML中的文件名(没有文件扩展名)。我也相信是文件类型本身和图像是否真的有一个透明的背景,决定它是否透明地出现在丝带。jpg文件不能透明,所以这可能是您的问题所在。如果您的UI编辑器不能容纳PNG文件,请尝试使用GIF。图标太小了,图像质量不应该成为问题。
下面是一个示例:
<splitButton id="splitButton2" size="large" >
<button id="InsertTools" label="Insert" image="InsertTools_Transparent" />
<menu id="menu2">
<button id="buttonInsertMultiSheets" onAction="ModRibbon.Run_InsertMultipleSheets" label="Insert Multiple Sheets" screentip="Add multiple worksheets at one time. An input box will appear for you to enter the number of sheets to be added." image="WorksheetAddMultipleSheets" />
</menu>
</splitButton>以下是我在学习时的一些个人笔记,它们可能对你有帮助,也可能没有帮助。
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<backstage>
<button id="MyCustomButton1" label="My Macro"
imageMso="HappyFace" isDefinitive="true" onAction="ModRibbon.Run_Macro1"/>
<!-- 'button id' each must be unique -->
<!-- 'My Macro' is the text that will appear on your button -->
<!-- Use 'imageMso' or 'image' to include a picture on your button. -->
<!-- 'imageMso' uses built-in Office images; do not insert into this file as icons. -->
<!-- 'image' uses your own image as your button's icon. Insert it into this file as an icon. -->
<!-- 'HappyFace' is the name of the built-in Office image (for custom images, enter the file name). -->
<!-- 'ModRibbon' is the name of the VBA module in which you will paste this call-back sub. You can name this anything. -->
<!-- 'Run_' is a custom prefix added to the macro name, so you don't have to rename your macros. -->
<!-- 'Macro1' is the macro that should be run when the button is clicked. -->
</backstage>
</customUI>使用我使用的自定义UI编辑器,回调将是:
'Callback for buttonInsertMultiSheets onAction
Sub Run_InsertMultipleSheets(control As IRibbonControl)
End Sub从您的代码中,您似乎也需要一个调用来加载映像,因此customUI控件有两个回调:
Sub LoadImage (imageID As String, ByRef image)
Sub OnLoad(ribbon As IRibbonUI)如果您也有一个Content_Types.xml,那么默认类型是PNG,您需要在文件的末尾添加一行,但是在前面添加一行,然后保存更改。
<Default Extension="jpg" ContentType="application/octet-stream"/>发布于 2019-06-13 07:47:02
在Ribbon上推荐的图标文件格式是PNG。Microsoft Office丝带和工具栏支持ICO、BMP和ICO文件。因此,我建议将您的VBA宏转换为COM外接程序,在这里您可以轻松地加载这样的图像。
您可能会发现Microsoft外接程序的图形格式的文章很有帮助。在以下系列文章中对Fluent UI进行了深入的描述:
https://stackoverflow.com/questions/56507603
复制相似问题