I'm currently working on creating my first ever Office 365 plugin specifically for Excel. I would like this plugin to be able to make REST API calls to an external service(either a micro service or a Lambda). I haven't written the REST service yet but want to know if this is even remotely possible from within Office JS. I found a similar question asked Use Office.js APIs from outside an Office Add in back in 2016 when Office-JS was brand new. Just wanted to know if there is better support for REST API from within Office-JS and if so where can i find specific documentation to accomplish this.
Yes. You can do this. Any REST API that can be called in a web app can be called from an Excel Add-in because the add-in essentially a web app embedded in Excel. E.g., the same ajax request that would work in a web app would work in the add-in.
I think the question that you linked to is different. It seems to be about the Excel REST APIs which are not the same as the Office.js.
Related
Q1. Are there any method to distribute excel office add-in(w/ office.js) in privately?
(Will office.js add-in also be distributed like VSTO's .exe OR .xla/.xlam macro files with password?)
Q2. If I run office add-in server(node.js) on my on-premise server, What will have to be distributed to the end-users?
(I want to hide the core source logic unlike VBA macro.)
I am now developing an excel office add-in. But there seems to be some limitation to deploy to the end-users in my company.(We are now testing environment for pilot, and using office 365 but it is restricted by IT's policy)
When I refer to the official documentation below, the docs says that the way to deploy add-in in privately are Microsoft 365 admin center OR SharePoint catalog.(AppSource is publicly for everyone.)
refer. https://learn.microsoft.com/en-us/office/dev/add-ins/publish/publish
However, it seems that it have to use Microsoft's services or components like SharePoint or admin center. I don't want to use these items because I want to flexibly cope with various environments.
I have also read the article as below.
refer. How to distribute private office add-ins?
But the reply thread seems that the writer couldn't get the appropriate answer what I also want to know.
I want to know the other ways to distribute excel office add-in(w/ office.js) without unveiling my core source logic and what is the minimum materials I have to provide to the end-users(i.g. manifest or something).
Typically, as you have already know, you need to host the add-in's source code on the web server anywhere. The manifest file just refers to the place where the sources are stored. And the single file which should be provided to be able to side-load add-ins locally is the manifest file. Everything else is hosted under your control.
Due to the nature of the web technology you can't hide the source code from users. The add-in acts like a regular web page. The best what you could do is to obfuscate your code.
(Desktop version) I'm new to using the javascript API for excel, but is it possible to create an excel add-in and share with other users without having to add the add-in to an app source etc? Can it be embedded in the excel file etc. I'd like to share scripts with other users the same way that I can share VBA if it's possible?
for security reasons as well as to make manageability of your add-ins easier, we do not store the code within the workbook, like VBA. Instead, the javascript is hosted on your website and we have a reference to your add-in saved in the workbook.
What this means, is to get a similar experience to VBA, you must either have the add-in hosted on app source (which will make it accessible via the Office Store), OR each user in an organization must have the add-in deployed or available to them (here we recommend centralized deployment as it will give the most robust experience).
This has all the current deployment options you can use for Office add-ins: https://learn.microsoft.com/en-us/office/dev/add-ins/publish/publish
thanks!
Is it possible to make web requests to an external url to grab data or post data to?
This way you can easily get data from external API's.
Here's the document to doing web requests in Office Scripts
https://learn.microsoft.com/en-us/office/dev/add-ins/excel/custom-functions-web-reqs?view=word-js-preview
Please note that there is JavaScript for Office Add-ins (https://learn.microsoft.com/en-us/office/dev/add-ins/?view=word-js-preview) and should be tagged #office-js.
This type of JavaScript can be used in different Office applications (web and desktop) to create add-ins that will work in both web apps and desktop applications.
This Office JavaScript API can be explored using Script Lab.
The tag #Office-Scripts reference Office Scripts for Excel on the web (https://learn.microsoft.com/en-us/office/dev/scripts/) which is also in preview and currently only available in Excel on the Web.
It can be enabled from the Admin portal of Microsoft365 (Formerly Office 365) under Settings/Settings and appears in Excel on the Web as a new tab called Automation.
It gives users the possibility to record macros and create scripts via the Office Scripts editor pane. Office-Scripts for Excel on the Web uses TypeScript. It is more limited in its scope than Office Add-in JavaScript.
So, to answer the question with regards to Office-Scripts for Excel on the Web, and as stated in the documentation, it is currently not possible to reference external API.
Read more here: https://learn.microsoft.com/en-us/office/dev/scripts/resources/add-ins-differences
Am I right to conclude that I may have to wait for certain objects and methods to appear in order to launch one office App from another?
I'm trying to link a number of Excel lines (customer interactions) one to one with OneNote pages.
I cannot find Office-js methods equivalent to those used in this VBA. I looked in the Office.js documentation and see only a couple of methods.
It is perfectly possible that I'm barking up the wrong tree.
This isn't possible with using Office.js. It's important to remember that each Web Add-in runs within its own sandbox and is essentially just a web app. It simply isn't possible for a Web Add-in to determine what other applications you have and remotely execute code against them (nor would you really want this if you consider the potential security risks that would open up).
What you can do however is leverage Microsoft Graph to interact with OneNote. So rather than having Excel drive OneNote over COM, you have your Web Add-in act as middleware between the current Excel Worksheet and a user's OneNote Notebook. You Add-in uses Office.js to communicate with the Worksheet and make REST calls to Microsoft Graph to interact the Notebook.
The first thing you'll need is an Access Token for the Excel user to use with Microsoft Graph. You can obtain this using the getAccessToken() method in Office.js. The steps for setting this up can be found at Authorize to Microsoft Graph in your Office Add-in (preview).
The second thing you'll need is to call Microsoft Graph. Assuming you want to keep things simple, I would use the Microsoft Graph Client SDK for Javascript for this. You'll also want to take a look at the OneNote API overview
from Microsoft Graph's documentation.
There are also some samples in OneNote's GitHub. Although none of the samples are exactly what you're looking for, they may still provide some valuable insights into how the API works.
I'm currently developing a tool using the Office javascript API. However, I would like to provide an own Excel function (something like =SUM(A1:A5)), which is based on code in C#.
Is there any way to avoid shipping two individual plug-ins from the users point of view? Can I combine both technologies to one plug-in?
If you are only targeting the desktop version of Excel then you can create a VSTO add-in instead of a JavaScript-based add-in. Within this adding you can include the code for your custom functions in the VSTO project and make sure they are correctly registered. One solution could be to create your own MSI-based installer, e.g. using Windows Installer XML (WIX) or Nullsoft's NSIS tool.
With this "classic" VSTO add-in technology you won't be able to target Excel on Mac, on mobile platforms or Excel Online in the browser though.
Yes there is also an alternative solution to creating a desktop C# add-in with VSTO or ExcelDNA as suggested by Dirk.
A javascript web add-in is just a web page with a library : office.js filling the gap between your logic and the office host application.
Why not passing the input to an API written in C# (this can be or not the same server serving the add-in) that will do the calculation ? The javascript will be there only to pass data and set the calculation results in spreadsheet.
I use ILMerge to combine my dlls. You can add it as a post build command so that they are merged on successful build.