Name: Office-OOXML-EmbedAddin
Owner: Office Developer
Description: Web application that uses Open XML SDK to configure Office documents to automatically open a specified add-in.
Created: 2017-06-13 17:42:04.0
Updated: 2017-07-13 23:00:23.0
Pushed: 2017-12-28 21:32:55.0
Homepage: null
Size: 20
Language: C#
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
The are a number of scenarios in which an Office Add-in should be embedded in an Office document and automatically open when the document opens.
Note: For more information about automatically opening an add-in in a document, see Automatically open a task pane with a document.
This sample uses .NET and the Open XML SDK to configure Office documents with the markup that makes this possible. In this sample, the Script Lab add-in is embedded in an Office file of the user's choice.
June 15, 2017:
Clone or download this repo.
Open the Office-OOXML-EmbedAddin.sln file in Visual Studio.
In Visual Studio add references to these assemblies:
Press F5. This opens the home page of the application in your browser.
Use the Browse control on the page to navigate to any Excel, Word, or PowerPoint file.
Press Upload.
Optional. If there is a particular snippet that you want to import as soon as Script Lab runs, enter its Gist ID in the textbox.
Note: This feature may not be supported in Script Lab for a short period after this sample is released. But it will do no harm to enter a Gist ID.
Press Embed Script Lab.
Press Download and follow your browser's prompts to open or save the file. When the file opens, the task pane opens and near the top, you are prompted to trust Script Lab (unless you already had it installed). When you do, Script Lab opens.
To verify that Script Lab is embedded in the document, close the file and reopen it. Script Lab opens in the task pane immediately.
The file Home.aspx.cs:
The file AddInEmbedder.cs:
The file OOXMLHelper.cs:
There are two critical lines in this file.
First, is the line in the GenerateWebExtensionPart1Content
method that sets the reference to Script Lab (strictly speaking, to the manifest for Script Lab):
ebExtensionStoreReference webExtensionStoreReference1 = new We.WebExtensionStoreReference() { Id = "wa104380862", Version = "1.1.0.0", Store = "en-US", StoreType = "OMEX" };
In this code:
If you were setting up an add-in from a file share catalog for auto-open, you would use different values:
Note: For more information about alternative values for these attributes, see Automatically open a task pane with a document.
Second, is the line in the GeneratePartContent
method that specifies the visibility of the taskpane when the file opens.
.WebExtensionTaskpane webExtensionTaskpane1 = new Wetp.WebExtensionTaskpane() { DockState = "right", Visibility = true, Width = 350D, Row = (UInt32Value)4U };
In this code, the Visibility
property of the WebExtensionTaskpane
object is set to true
. The effect of this is that the very first time that the file is opened after the code is run, the task pane opens with Script Lab in it (after the user accepts the prompt to trust Script Lab). This is what we want for this sample. However, in most scenarios you will probably want this set to false
. The effect of setting it to false is that the first time the file is opened, the user has to install the add-in, from the Add-in button on the ribbon. On every subsequent opening of the file, the taskpane with the add-in opens automatically.
The advantage of setting this property to false
is that you can use the Office.js to turn give users the ability to turn on and off the auto-opening of the add-in. Specifically, your script sets the Office.AutoShowTaskpaneWithDocument document setting to true
or false
. However, if WebExtensionTaskpane.Visibility
is set to true
, there is no way for Office.js or, hence, your users to turn off the auto-opening of the add-in. Only editing the OOXML of the document can change WebExtensionTaskpane.Visibility
to false.
Note: For more information about task pane visibility at the level of the Open XML that these .NET APIs represent, see Automatically open a task pane with a document.
We'd love to get your feedback about this sample. You can send your feedback to us in the Issues section of this repository.
Questions about Microsoft Office 365 development in general should be posted to Stack Overflow. If your question is about the Office JavaScript APIs, make sure that your questions are tagged with [office-js].
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.