我正在尝试按照官方文档开发内容插件。实现部分指出只需要进行少量更改:
- 对于 OfficeApp 元素,将 xsi:type 属性设置为“ContentApp”。
- 在
DefaultSettings
元素中,添加RequestedHeight
和RequestedWidth
元素。
在同一部分中,列出了两个适用于 PowerPoint 和 Excel 的基于内容的入门插件,但遗憾的是它们针对的是 Visual Studio,而我没有 Windows 电脑。此外,还提到了一个已有 9 年历史的示例Excel-Content-Add-in-Humongous-Insurance,其清单看起来相当过时。
我决定尝试使用 Yeoman 和 VScode。由于yo office
Office 不提供基于内容的插件入门,我选择使用:
? Choose a project type: Office Add-in Task Pane project using React framework
? Choose a script type: TypeScript
? What do you want to name your add-in? my-content-addin
? Which Office client application would you like to support? Powerpoint
按照上面列出的文档,我将元素xsi:type
的更改OfficeApp
为,并将和元素ContentApp
添加到元素。RequestedHeight
RequestedWidth
DefaultSettings
此外,我注意到Excel-Content-Add-in-Humongous-Insurance清单在 OfficeApp 中没有以下模式:
xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides"
我检查了 office-addin-manifest 存储库,但找不到内容插件的替代方案,例如,.../contentappversionoverrides
我只找到了一个额外的.../mailappversionoverrides
。
我还注意到Excel-Content-Add-in-Humongous-Insurance清单中没有该VersionOverrides
元素,因此我从生成的清单中删除了该元素manifest.xml
。因此,我最终得到了:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp
xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
xsi:type="ContentApp">
<Id>9e2e38ec-67af-43e6-8aeb-c8c3e22b86bd</Id>
<Version>1.0.0.0</Version>
<ProviderName>Contoso</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<DisplayName DefaultValue="my-content-addin"/>
<Description DefaultValue="A template to get started."/>
<IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
<HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-64.png"/>
<SupportUrl DefaultValue="https://www.contoso.com/help"/>
<AppDomains>
<AppDomain>https://www.contoso.com</AppDomain>
</AppDomains>
<Hosts>
<Host Name="Presentation"/>
</Hosts>
<DefaultSettings>
<SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
<RequestedHeight>400</RequestedHeight>
<RequestedWidth>400</RequestedWidth>
</DefaultSettings>
<Permissions>ReadWriteDocument</Permissions>
</OfficeApp>
之后我尝试验证清单并收到以下错误:
Error #1:
XML Schema Validation Error: Error found during XML Schema validation.
- Details: The element 'DefaultSettings' in namespace 'http://schemas.microsoft.com/office/appforoffice/1.1' has invalid child element 'RequestedWidth' in namespace 'http://schemas.microsoft.com/office/appforoffice/1.1'.
- Line: 25
- Column: 6
Error #2:
XML Schema Violation: Your manifest does not adhere to the current set of XML schema definitions for Office Add-in manifests.
我删除了它,尽管它似乎被模块RequestedWidth
识别,然后重试。这次清单是有效的。因此,我运行了,我的插件自动添加到了当前幻灯片中。manifestHandlerXml.ts
office-addin-manifest
npm start
这是我的最终 manifest.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp
xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
xsi:type="ContentApp">
<Id>9e2e38ec-67af-43e6-8aeb-c8c3e22b86bd</Id>
<Version>1.0.0.0</Version>
<ProviderName>Contoso</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<DisplayName DefaultValue="my-content-addin"/>
<Description DefaultValue="A template to get started."/>
<IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
<HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-64.png"/>
<SupportUrl DefaultValue="https://www.contoso.com/help"/>
<AppDomains>
<AppDomain>https://www.contoso.com</AppDomain>
</AppDomains>
<Hosts>
<Host Name="Presentation"/>
</Hosts>
<DefaultSettings>
<SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
<RequestedHeight>400</RequestedHeight>
</DefaultSettings>
<Permissions>ReadWriteDocument</Permissions>
</OfficeApp>
如何为我的内容插件指定默认宽度?
如何仅当我单击功能区命令(如默认 TaskPane 演示打开任务窗格)时插入我的插件?
在 Yeoman Taskpane Demo 中,VersionOverrides
需要一个 schema xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides"
。
action 元素的替代方案是什么Control
?<Action xsi:type="ShowTaskpane">
是在基于内容的插件中吗?
必须
<RequestedWidth>
刚好位于 之上<RequestedHeight>
。内容插件无法在功能区中添加按钮。插件安装后,内容会立即插入到打开的 Office 文档中。