设置透明图标与 Excel 中的功能区 API 不起作用



我正在尝试使用 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 Resourcesiconsgg.ico")
End Sub

我将 gg.ico 保存在 GIMP 中为 24 bpp 和 1 位 alpha ico 文件。我也尝试了外部 ico-s,但它们也没有显示。

正如您从上面了解到的那样,图标不会像完全透明一样显示。

你能帮忙吗?

另外,是否仍支持此 RibbonX API?我很想知道,因为我在做一件非常基本的事情时遇到困难,并且几乎找不到文档。如果不是,用于开发具有可自定义功能区的 Excel 加载项的新式框架是什么?

谢谢。

自定义功能区 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"/>

功能区 UI 上图标的建议文件格式为 PNG。Microsoft Office 功能区和工具栏支持 ICO、BMP 和 ICO 文件。因此,我建议将VBA宏转换为COM加载项,您可以在其中轻松加载此类图像。

您可能会发现 Office 外接程序的图形格式Microsoft文章很有帮助。以下系列文章将深入介绍 Fluent UI:

  • 为开发人员自定义 2007 Office Fluent 功能区(第 1 部分,共 3 部分)
  • 为开发人员自定义 2007 Office Fluent 功能区(第 2 部分,共 3 部分)
  • 为开发人员自定义 2007 Office Fluent 功能区(第 3 部分,共 3 部分)

最新更新