简体   繁体   English

如何在Office JavaScript API中获取当前的Excel文件?

[英]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.

相关问题 如何在Office Javascript API中读取Excel自定义属性? - How can I read Excel custom properties in Office Javascript API? 使用JavaScript API for Office获取Excel范围 - Get Excel range using JavaScript API for Office Office Javascript API:如何手动触发MS Office的自动套用格式功能? - Javascript API for Office: How Can I Manually Trigger MS Office's AutoFormat Functionality? 使用Office Javascript API获取当前句子 - Getting current sentence using Office Javascript API Office JavaScript API for Outlook-位置更改时如何刷新我的Web加载项? - Office JavaScript API for Outlook - how can I refresh my web add-in when location changes? 我如何在 API javascript 中获取数据? - how can i get data in API javascript? Office的JavaScript API:如何获取当前选择的单元格标识符? - JavaScript API for Office: How to get currently selected cell identifier? 如何从Office365中的JavaScript API获取重复数据 - How to get recurrence data from JavaScript API in office365 如何在 Javascript 中获取当前目录名称? - How can I get the current directory name in Javascript? 如何获取JavaScript中的当前桌面路径? (Windows 7的) - How can I get the current desktop path in JavaScript? (Windows 7)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM