How do i get the file token for an embedded Excel spreadsheet?

Viewed 514

I have an ASP.Net Web application where I embed an interactive Excel spreadsheet. The user should be able to interact with the spreadsheet. I embedded the spreadsheet with code from Office Support. The embedding itself works to an extent-- user can click around, but webpage gets no info.

In order to get more info, and be able to write using an ASP.Net Button I turned to an example using the Excel Services ECMAScript (JavaScript) API. The one thing causing problems is the line:

var fileToken = "SD310A16DD64ED7E41!112/3533661997762444865/";

I tried finding the token using the example here.

The embed code in this particular example is:

<iframe title ="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" width="402px" height="346px" style="padding:0;background-color:#fcfcfc;" src="https://r.office.microsoft.com/r/rlidExcelEmbed?su=-5430218907388983095&Fi=SDB4A3FCAC9C7848C9!285&ak=t%3d0%26s%3d0%26v%3d!AJHqJpkd-Q5axR8&kip=1"></iframe>

and the file token is:

SDB4A3FCAC9C7848C9!285/-5430218907388983095/t=0&s=0&v=!AK3ybHnbJCLh5H0.

This example was not helpful at all because my embed code is of the form:

https://onedrive.live.com/embed?resid=2EE19DD0B45C2F85%2156366&authkey=%21AC2IkSn6J6_kejU&em=3&wdDivId=%22myExcelDiv%22&wdDownloadButton=1&wdHideGridlines=1&wdHideHeaders=1&wdAllowInteractivity=0&wdAllowTyping=1.

Therefore it has been pretty impossible to find the token in the manner of the example.

I tried using 2EE19DD0B45C2F85%2156366 as the file token but the code I copied from the ECMAScript API returns the error: Async operation failed!.

How can I find the file token for my embedded Excel spreadsheet?

2 Answers

Okay after a lot of digging around I finally got how to gain control of the embedded excel in Javascript. Technically this may not answer your question "How to get the file token for the embedded excel spreadsheet", but I'm assuming you want that token to control the embedded excel in javascript. Instead of initializing the embedded excel through the EWA instance, you want to initialize the excel using the javascript embed code that you will find on onedrive. Then after the instance is application ready (you can find out how to attach a callback to this in the link below) you can simply fetch the instance of the embedded excel using this

ewa = Ewa.EwaControl.getInstances().getItem(0);

More information at this link: https://github.com/SharePoint/sp-dev-docs/blob/master/docs/general-development/working-with-the-excel-services-javascript-object-model.md

It appears that the example you were using is based on an earlier version of the One Drive JavaScript API, from MS SharePoint 2010. Microsoft have since superseded it with the OneDrive Developer Platform (part of their Microsoft Graph APIs). Check out the official docs here: MS OneDrive Developer Platform.

I've also been recently searching for a JavaScript-only solution to sharing spreadsheets online with more functionality than the embed option allows. ODDP appears to be the way forward.

Related