使用JavaScript从OneDrive/SharePoint位置读取Excel文件 [英] Reading Excel file from OneDrive/SharePoint location using JavaScript

查看:109
本文介绍了使用JavaScript从OneDrive/SharePoint位置读取Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试 使用JavaScript从OneDrive/SharePoint位置读取Excel文件的内容 ,但是没有做即使经过多次尝试.

I have been trying to read an excel file's content from OneDrive/SharePoint location using JavaScript but failing to do so even after many tries.

尝试#1. Ajax查询到URL的位置.正如预期的那样,CORS错误!

Attempt#1. Ajax query to the URL location. CORS error, as expected!

--------------------------------------------------- -------------------------------------------------- ----------------------

-----------------------------------------------------------------------------------------------------------------------

尝试#2.使用XMLHttpRequest的CORS请求. 由CORS策略阻止:在所请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许访问原始空".错误!

Attempt#2. CORS request using XMLHttpRequest. "blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access." Error!

--------------------------------------------------- -------------------------------------------------- ----------------------

-----------------------------------------------------------------------------------------------------------------------

尝试#3.适用于JavaScript的OneDrive文件选择器-https://docs.microsoft.com/zh-cn/onedrive/developer/controls/file-pickers/js-v72/index 

Attempt#3. OneDrive file picker for JavaScript - https://docs.microsoft.com/en-us/onedrive/developer/controls/file-pickers/js-v72/index 

错误#1.我们无法完成您的请求
Microsoft帐户遇到技术问题.请稍后再试.

Error#1. We're unable to complete your request
Microsoft account is experiencing technical problems. Please try again later.

--------------------------------------------------- -------------------------------------------------- ----------------------

-----------------------------------------------------------------------------------------------------------------------

尝试#4. OneDrive SDK-  https://msdn.microsoft.com/en-us/library/hh243643.aspx

Attempt#4. OneDrive SDK - https://msdn.microsoft.com/en-us/library/hh243643.aspx

错误#1. (在弹出窗口中)我们无法完成您的请求
Microsoft帐户遇到技术问题.请稍后再试.

Error#1. (on the popup window)We're unable to complete your request
Microsoft account is experiencing technical problems. Please try again later.

错误#2.由于将"X-Frame-Options"设置为"deny",因此拒绝显示在框架中.

Error#2. Refused to display in a frame because it set 'X-Frame-Options' to 'deny'.

错误#3 [WL] WL.login:弹出窗口未得到同意即被关闭.

Error#3 [WL]WL.login: The popup is closed without receiving consent.

--------------------------------------------------- -------------------------------------------------- ----------------------

-----------------------------------------------------------------------------------------------------------------------

现在,我担心的是这样做是否可行?如果是, 如何?

Now, my concern is if it is even feasible to do so? if yes, how?

推荐答案

您可以通过某些js库(例如xlsx-populate)读取/写入xlsx文件.

You could read/write xlsx file by some js library, for example xlsx-populate.

通过JSOM或PNP JS读取/写入SharePoint文件.

Read/write SharePoint file by JSOM or PNP JS.

https://github.com/SharePoint/PnP-JS-Core/wiki/工作方式:-文件

如果要自动执行此操作,则可以创建一个由提供程序托管的加载项并实现远程事件接收器,以便可以通过EPPLUS/NPOI读取/写入excel文件.

If you want to do this automatically, you could create a provider-hosted add-in and implement remote event receiver, so you could read/write excel file by EPPLUS/NPOI.

SharePoint远程事件接收器:

SharePoint remote event receiver:

EPPLUS的Excel操作:

Excel operations by EPPLUS:

https://www.nuget.org/packages/EPPlus/

请注意,如果要使用JavaScript在其他外部系统而不是SharePoint中调用相关的API,则无法避免跨域问题.对于这种情况,我们需要在SharePoint中创建自定义Web服务以实现此目的.

Pay attention, if you want to use JavaScript to call related API in other outside system instead of SharePoint, you can't avoid the problem of Cross-Domain. For this situation, we need to create a custom web service in SharePoint to achieve this.

最诚挚的问候,

李刘


这篇关于使用JavaScript从OneDrive/SharePoint位置读取Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆