[英]How can I get the current Excel file in Office JavaScript API?
I am developing a tab pane app in Excel which needs to read the current document. 我正在Excel中开发一个需要读取当前文档的选项卡窗格应用程序。 In Word, the Office JavaScript API has the method Office.context.document.getFileAsync(), but this is not available in Excel.
在Word中,Office JavaScript API具有Office.context.document.getFileAsync()方法,但这在Excel中不可用。
I can get the URL of the document with Office.context.document.getFileProperties(), and then I thought I could read the file with this. 我可以使用Office.context.document.getFileProperties()获取文档的URL,然后我想我可以用这个读取文件。
I tried using the HTML5 FileReader() object, but this only works for files selected from the file input control. 我尝试使用HTML5 FileReader()对象,但这仅适用于从文件输入控件中选择的文件。 I tried manipulating a hidden file input control so it automatically uses the current document, but JavaScript understandably prevents you from doing this for security reasons.
我尝试操作隐藏文件输入控件,因此它会自动使用当前文档,但出于安全原因,JavaScript可以理解地阻止您执行此操作。 I could ask the user to browse to the document they are currently using but that would be a poor user experience.
我可以要求用户浏览他们当前使用的文档,但这将是一个糟糕的用户体验。
So I tried using ActiveXObject('Scripting.FileSystemObject') but ActiveX is not allowed in tab pane apps at all, whatever the current security setting are in IE. 所以我尝试使用ActiveXObject('Scripting.FileSystemObject'),但是在Tab窗格应用程序中根本不允许使用ActiveX,无论IE中当前的安全设置如何。
What other options do I have? 我还有其他选择吗?
According to the API road map, Office.context.document.getFileAsync() is not available in Excel at this moment. 根据API路线图,此时Excel中没有Office.context.document.getFileAsync()。
I don't think it's feasible by using getFilePropertiesAsync(). 我不认为使用getFilePropertiesAsync()是可行的。 It only returns the URL.
它只返回URL。 Usually browser forbids developer touching any content in the file system.
通常浏览器禁止开发人员触摸文件系统中的任何内容。 Therefore, it's hard to access the local file system in JavaScript code.
因此,很难在JavaScript代码中访问本地文件系统。
Besides, the file may not be in local file system. 此外,该文件可能不在本地文件系统中。 For example, it could be hosted in Onedrive or SharePoint.
例如,它可以托管在Onedrive或SharePoint中。 getFilePropertiesAsync() should return its real URL in Onedrive/SharePoint, instead of local file system.
getFilePropertiesAsync()应该在Onedrive / SharePoint中返回其真实URL,而不是本地文件系统。
I guess Microsoft will support getFileAsync() in the future. 我想微软将来会支持getFileAsync()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.