在SharePoint联机文档库中使用REST API创建.docx文件 [英] Create a .docx file using REST API in SharePoint online document library

查看:75
本文介绍了在SharePoint联机文档库中使用REST API创建.docx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

我正在尝试使用REST,Javascript和HTML在线创建一个.docx文件到Sharepoint文档库中。 

I am trying to create a .docx file into a document library in Sharepoint online using REST, Javascript and HTML. 

如果.docx文件中没有数据,则word文档正常打开(当然它是空的)。 

If no data are included into the .docx file the word document opens normally (and of course it's empty). 

如果数据包含在。 docx文件尝试使用Word Online或Word打开它时出错。 

If data are included into the .docx file I am getting an error when trying to open it either with Word Online or Word. 

错误消息是"抱歉,无法打开此文档进行编辑。告诉我们这个问题,以帮助我们解决它'和'我们很抱歉。我们无法打开xyz.docx,因为我们发现它的内容分别存在问题。

The error messages are 'Sorry, this document can't be opened for editing. Tell us about this problem to help us fix it' and 'We're sorry. We can't open xyz.docx because we found a problem with it's contents' respectively.

我的代码有问题吗? 

Is there something wrong with my code? 

提前致谢。 

Thanks in advance. 

我正在使用的REST代码如下;

The REST code I am using is the below;

推荐答案

办公室文件不仅仅是简单文本,还包含许多元数据信息。

在这种情况下,有两种解决方案。

在本地创建docx文件,然后通过REST api上传到SharePoint。

以下官方指南共享一个很好的样本。

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/upload-a-file-by -using-the-rest-api-and-jquery

或者,用第三个创建docx文件 - 图书馆。

https: //github.com/dolanmiu/docx

然后,将文件内容读取为arraybuffer和upload。

https://stackoverflow.com/questions/15341912/how-to-go-from-blob-to-arraybuffer

最好的问候,

Lee


这篇关于在SharePoint联机文档库中使用REST API创建.docx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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