昨年末に書いた記事で「アドイン コマンド」を紹介しているのですが、知らないうちにPowerPointも対応していたようなので、さっそく試してみました。
必要な環境
- 16.0.6568.2025 以上のバージョンのPowerPoint
- 機能を有効化するためのレジストリキー
マニフェストファイル
<?xml version="1.0" encoding="utf-8"?>
<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"
xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides"
xsi:type="TaskPaneApp">
<Id>3ed7de23-9a21-4b2a-9205-4a9e515331c0</Id>
<Version>1.0.0.0</Version>
<ProviderName>kinuasa</ProviderName>
<DefaultLocale>ja-JP</DefaultLocale>
<DisplayName DefaultValue="Sample Command App 01" />
<Description DefaultValue="Sample Command App Description" />
<Hosts>
<Host Name="Presentation" />
</Hosts>
<DefaultSettings>
<SourceLocation DefaultValue="https://localhost/apps/command01.html" />
</DefaultSettings>
<Permissions>ReadWriteDocument</Permissions>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
<Hosts>
<Host xsi:type="Presentation">
<DesktopFormFactor>
<FunctionFile resid="residDesktopFuncUrl" />
<ExtensionPoint xsi:type="PrimaryCommandSurface">
<!-- TabAddIns Start -->
<OfficeTab id="TabAddIns">
<!-- grpSample Start -->
<Group id="grpSample">
<Label resid="residGrpSampleLabel" />
<Icon>
<bt:Image size="16" resid="residIcon16" />
<bt:Image size="32" resid="residIcon32" />
<bt:Image size="80" resid="residIcon80" />
</Icon>
<!-- btnSample Start -->
<Control xsi:type="Button" id="btnSample">
<Label resid="residBtnSampleLabel" />
<Supertip>
<Title resid="residBtnSampleTitle" />
<Description resid="residBtnSampleDesc" />
</Supertip>
<Icon>
<bt:Image size="16" resid="residIcon16" />
<bt:Image size="32" resid="residIcon32" />
<bt:Image size="80" resid="residIcon80" />
</Icon>
<Action xsi:type="ShowTaskpane">
<SourceLocation resid="residTaskpaneUrl" />
</Action>
</Control>
<!-- btnSample End -->
<!-- btnSample2 Start -->
<Control xsi:type="Button" id="btnSample2">
<Label resid="residBtnSampleLabel2" />
<Supertip>
<Title resid="residBtnSampleTitle2" />
<Description resid="residBtnSampleDesc2" />
</Supertip>
<Icon>
<bt:Image size="16" resid="residIcon16" />
<bt:Image size="32" resid="residIcon32" />
<bt:Image size="80" resid="residIcon80" />
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>btnSample_onAction</FunctionName>
</Action>
</Control>
<!-- btnSample2 End -->
<!-- menuSample Start -->
<Control xsi:type="Menu" id="menuSample">
<Label resid="residMenuSampleLabel" />
<Supertip>
<Title resid="residMenuSampleTitle" />
<Description resid="residMenuSampleDesc" />
</Supertip>
<Icon>
<bt:Image size="16" resid="residIcon16" />
<bt:Image size="32" resid="residIcon32" />
<bt:Image size="80" resid="residIcon80" />
</Icon>
<Items>
<!-- itmSample Start -->
<Item id="itmSample">
<Label resid="residItmSampleLabel"/>
<Supertip>
<Title resid="residItmSampleTitle" />
<Description resid="residItmSampleDesc" />
</Supertip>
<Icon>
<bt:Image size="16" resid="residIcon16" />
<bt:Image size="32" resid="residIcon32" />
<bt:Image size="80" resid="residIcon80" />
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>btnSample_onAction</FunctionName>
</Action>
</Item>
<!-- itmSample End -->
<!-- itmSample2 Start -->
<Item id="itmSample2">
<Label resid="residItmSampleLabel2"/>
<Supertip>
<Title resid="residItmSampleTitle2" />
<Description resid="residItmSampleDesc2" />
</Supertip>
<Icon>
<bt:Image size="16" resid="residIcon16" />
<bt:Image size="32" resid="residIcon32" />
<bt:Image size="80" resid="residIcon80" />
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>btnSample_onAction</FunctionName>
</Action>
</Item>
<!-- itmSample2 End -->
</Items>
</Control>
<!-- menuSample End -->
</Group>
<!-- grpSample End -->
</OfficeTab>
<!-- TabAddIns End -->
</ExtensionPoint>
<ExtensionPoint xsi:type="ContextMenu">
<!-- ContextMenuText Start -->
<OfficeMenu id="ContextMenuText">
<!-- menuSample2 Start -->
<Control xsi:type="Menu" id="menuSample2">
<Label resid="residMenuSampleLabel2" />
<Supertip>
<Title resid="residMenuSampleTitle2" />
<Description resid="residMenuSampleDesc2" />
</Supertip>
<Icon>
<bt:Image size="16" resid="residIcon16" />
<bt:Image size="32" resid="residIcon32" />
<bt:Image size="80" resid="residIcon80" />
</Icon>
<Items>
<!-- itmSample3 Start -->
<Item id="itmSample3">
<Label resid="residItmSampleLabel3"/>
<Supertip>
<Title resid="residItmSampleTitle3" />
<Description resid="residItmSampleDesc3" />
</Supertip>
<Icon>
<bt:Image size="16" resid="residIcon16" />
<bt:Image size="32" resid="residIcon32" />
<bt:Image size="80" resid="residIcon80" />
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>btnSample_onAction</FunctionName>
</Action>
</Item>
<!-- itmSample3 End -->
<!-- itmSample4 Start -->
<Item id="itmSample4">
<Label resid="residItmSampleLabel4"/>
<Supertip>
<Title resid="residItmSampleTitle4" />
<Description resid="residItmSampleDesc4" />
</Supertip>
<Icon>
<bt:Image size="16" resid="residIcon16" />
<bt:Image size="32" resid="residIcon32" />
<bt:Image size="80" resid="residIcon80" />
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>btnSample_onAction</FunctionName>
</Action>
</Item>
<!-- itmSample4 End -->
</Items>
</Control>
<!-- menuSample2 End -->
</OfficeMenu>
<!-- ContextMenuText End -->
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Images>
<bt:Image id="residIcon16" DefaultValue="https://localhost/apps/img/icon16.png" />
<bt:Image id="residIcon32" DefaultValue="https://localhost/apps/img/icon32.png" />
<bt:Image id="residIcon80" DefaultValue="https://localhost/apps/img/icon80.png" />
</bt:Images>
<bt:Urls>
<bt:Url id="residDesktopFuncUrl" DefaultValue="http://localhost/apps/func.html" />
<bt:Url id="residTaskpaneUrl" DefaultValue="http://localhost/apps/command01.html" />
</bt:Urls>
<bt:ShortStrings>
<bt:String id="residGrpSampleLabel" DefaultValue="Sample Group" />
<bt:String id="residBtnSampleLabel" DefaultValue="Sample Button" />
<bt:String id="residBtnSampleLabel2" DefaultValue="Sample Button 2" />
<bt:String id="residMenuSampleLabel" DefaultValue="Sample Menu" />
<bt:String id="residMenuSampleLabel2" DefaultValue="Sample Menu 2" />
<bt:String id="residItmSampleLabel" DefaultValue="Sample Menu Item" />
<bt:String id="residItmSampleLabel2" DefaultValue="Sample Menu Item 2" />
<bt:String id="residItmSampleLabel3" DefaultValue="Sample Menu Item 3" />
<bt:String id="residItmSampleLabel4" DefaultValue="Sample Menu Item 4" />
<bt:String id="residBtnSampleTitle" DefaultValue="Sample Button SuperTip Title" />
<bt:String id="residBtnSampleTitle2" DefaultValue="Sample Button 2 SuperTip Title" />
<bt:String id="residMenuSampleTitle" DefaultValue="Sample Menu SuperTip Title" />
<bt:String id="residMenuSampleTitle2" DefaultValue="Sample Menu 2 SuperTip Title" />
<bt:String id="residItmSampleTitle" DefaultValue="Sample Menu Item SuperTip Title" />
<bt:String id="residItmSampleTitle2" DefaultValue="Sample Menu Item 2 SuperTip Title" />
<bt:String id="residItmSampleTitle3" DefaultValue="Sample Menu Item 3 SuperTip Title" />
<bt:String id="residItmSampleTitle4" DefaultValue="Sample Menu Item 4 SuperTip Title" />
</bt:ShortStrings>
<bt:LongStrings>
<bt:String id="residBtnSampleDesc" DefaultValue="Sample Button SuperTip Description" />
<bt:String id="residBtnSampleDesc2" DefaultValue="Sample Button 2 SuperTip Description" />
<bt:String id="residMenuSampleDesc" DefaultValue="Sample Menu SuperTip Description" />
<bt:String id="residMenuSampleDesc2" DefaultValue="Sample Menu 2 SuperTip Description" />
<bt:String id="residItmSampleDesc" DefaultValue="Sample Menu Item SuperTip Description" />
<bt:String id="residItmSampleDesc2" DefaultValue="Sample Menu Item 2 SuperTip Description" />
<bt:String id="residItmSampleDesc3" DefaultValue="Sample Menu Item 3 SuperTip Description" />
<bt:String id="residItmSampleDesc4" DefaultValue="Sample Menu Item 4 SuperTip Description" />
</bt:LongStrings>
</Resources>
</VersionOverrides>
</OfficeApp>
せっかくなので今回はメニュー コントロールやコンテキスト メニューも使っています。
(アドイン コマンドを使えば使うほどコードが長くなってしまうのが鬱陶しいですが、そういう仕様なので仕方ありません・・・。)
command01.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title>Sample</title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.2.1.min.js"></script>
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
<script>
Office.initialize = function(reason){}
$(function(){
$("#btnTest").click(function(){
Office.context.document.setSelectedDataAsync("Hello World.");
});
});
</script>
</head>
<body>
<h4>Sample Page</h4>
<input id="btnTest" type="button" value="Test">
</body>
</html>
func.html
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
<script>
Office.initialize = function(reason){}
function btnSample_onAction(event){
var buttonId = event.source.id;
Office.context.document.setSelectedDataAsync(buttonId);
event.completed();
}
</script>
実行結果
上記アドインを実行した結果が下図になります。

タブやコンテキスト メニューのカスタマイズを行うと、シームレスにOffice アドインの機能を呼び出せます。
現時点(2016年3月)では実行可能なバージョンに制限があり、使い勝手が良いとは言えない機能ですが、今後Office 2016のシェアが拡大するにつれ、アドイン コマンドを実行できる環境も広がっていくだろうと思います。Office開発者の方は今から要チェックです!
参考資料
- Excel、Word および PowerPoint のアドイン コマンド (プレビュー)
- https://msdn.microsoft.com/ja-jp/library/mt607161.aspx
- Excel、Word、および PowerPoint のマニフェストでアドイン コマンドを作成する (プレビュー)
- https://msdn.microsoft.com/ja-jp/library/mt621545.aspx
- Office Add-in Commands Samples
- https://github.com/OfficeDev/Office-Add-in-Commands-Samples
- Install the latest version of Office 2016 applications
- https://github.com/OfficeDev/Office-Add-in-Commands-Samples/blob/master/Tools/LatestOfficeBuild.md
- Image callouts Word add-in sample: load, edit, and insert images
- https://github.com/OfficeDev/Word-Add-in-TypeScript-Canvas
- Silly stories Word add-in sample: load files and use content controls
- https://github.com/OfficeDev/Word-Add-in-SillyStories
特に「Excel、Word および PowerPoint のアドイン コマンド (プレビュー)」と「Excel、Word、および PowerPoint のマニフェストでアドイン コマンドを作成する (プレビュー)」の記事はオススメです。



















この記事へのコメントはありません。