How to get the current Excel file in the Office JavaScript API?

I am developing a tab bar application in Excel that needs to read the current document. In Word, the JavaScript API for Office has an Office.context.document.getFileAsync () method, but this is not available in Excel.

I can get the url of the document using Office.context.document.getFileProperties () and then I thought I could read the file with that.

I tried using the HTML5 FileReader () object, but this only works for files selected from the file input control. I've tried to manipulate the hidden file input control so it automatically uses the current document, but JavaScript seems to be preventing you from doing this for security reasons. I could ask the user to go to the document they are currently using, but that would be a bad user experience.

So, I tried using ActiveXObject ('Scripting.FileSystemObject'), but ActiveX is not allowed at all in tabbed apps, no matter what the current security setting is in IE.

What other options do I have?

+3


source to share


1 answer


According to the API roadmap, Office.context.document.getFileAsync () is currently not available in Excel.

I don't think this is possible using getFilePropertiesAsync (). It returns url only. Typically the browser prevents the developer from touching any content on the file system. Therefore, it is difficult to access the local filesystem in JavaScript code.



In addition, the file may not be present on the local file system. For example, it can be hosted on Onedrive or SharePoint. getFilePropertiesAsync () should return its real URL in Onedrive / SharePoint instead of the local filesystem.

I assume Microsoft will support getFileAsync () in the future.

+2


source







All Articles