Office 365-创建* .docx | * .pptx | * .xlsx文件 [英] Office 365 - Create *.docx | *.pptx | *.xlsx files

查看:109
本文介绍了Office 365-创建* .docx | * .pptx | * .xlsx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个Web项目,该项目使用OneDrive API进行文件管理.我想创建* .docx | * .pptx | * .xlsx文件,但是不幸的是,没有一个OneDrive API支持创建空文件/新文件.我试图将空白/新文件从服务器上载到OneDrive.尽管上传正常,但该文件无法在Office Online和本地Office中打开.

I'm working on a web project which uses the OneDrive API for file management purposes. I wanted to create *.docx | *.pptx | *.xlsx files but unfortunately, none of the OneDrive APIs support creating empty/new files. What I tried was to upload an empty/new file from my server to OneDrive. While the upload works fine, the file does not open in Office Online nor in local Office.

来自这个博客,我能够生成一个Word文件并将其上传.

From this blog, I was able to generate a Word file and upload it.

function createNewDoc(name) {
var htmlString = "<html><body></body></html>";
var byteNumbers = new Uint8Array(htmlString.length);

for (var i = 0; i < htmlString.length; i++) {
   byteNumbers[i] = htmlString.charCodeAt(i);
    }
    var blob = new Blob([byteNumbers], {type: "text/html"});
    socialAPI.uploadFile('windows', blob, 'name', 'folder.87ash7ashb7a2').then(function (resp) {
        console.log("response for uploading file", resp);
    })
}

此文件适用于Word.但是,该方法不适用于Excel和Powerpoint.

This file worked for Word. However, the method doesn't work for Excel and Powerpoint.

因此,最终,我无法使用OneDrive API进行任何操作.我开始查看Office 365 API,是否有可以创建上述文件的内容,但找不到类似的东西. (PS:我正在查看REST API)

So ultimately, I was not able to do anything using the OneDrive API. I started looking at Office 365 API if there's anything which allows creation of above mentioned files but I couldn't find anything like that. (P.S: I'm looking at REST APIs)

我注意到的另一件事是Box可以执行相同的操作并在窗口中将其打开,但是url的格式为 https://app.box.com/services/box_for_office_online . Box是否与Microsoft有一些特殊的合作以提供这样的服务?

Another thing I noticed is Box is able to do the same and open it in a window, but the url is in the format https://app.box.com/services/box_for_office_online. Does Box have some special collaboration with Microsoft to provide such a service?

推荐答案

空" Office文件并不是真正的0字节文件.桌面Office应用程序(Excel除外)能够获取0字节的文件并将其变成Office文档(插入使该文件成为Office文件的模板").在线Office应用程序当前不支持这样做.

"Empty" Office files aren't really 0 byte files. The desktop Office applications (except Excel) are able to take a 0 byte file and make it become an Office document (insert the "template" that makes a file an Office file). The online Office apps currently don't support doing that.

由于当前没有API可以创建特定类型的新文件,因此您需要解决该问题.为此,您需要存储和上传Word,Excel和PowerPoint的模板"文件.您提供的示例是针对Word执行此操作的一种方法,其中您创建了一个空的HTML页面并上传了该页面.

As there is no API currently to create a new file of a particular type, you'll need to work around it. To do this, you need to store and upload "template" files for Word, Excel, and PowerPoint. The example you provided is one way of doing this for Word, where you've created an empty HTML page and uploaded it.

对于Excel和PowerPoint,您将需要执行类似的操作,方法是创建一个空文件,并在应用程序要创建一个新的空文件时将其作为新"文件上传.但是,除了能够将简单的HTML字符串作为模板文件内容存储之外,您需要一个新文件的实际二进制内容,根据类型的不同,该二进制文件的最大长度约为30kb.

For Excel and PowerPoint, you would need to do something similar by creating an empty file and uploading that as the "new" file whenever your app wants to create a new empty file. However, instead of being able to store a simple HTML string as the template file content, you'll need the actual binary content of a new file, which can be up to ~30kb depending on the type.

我们正在努力改进Web应用程序,以便它们可以获取0字节的文件并将其转换"为新文档,但是今天仍然是一个错误.

We are working to improve the Web apps so they can take a 0 byte file and "convert" it into a new document, but that is still a bug today.

这篇关于Office 365-创建* .docx | * .pptx | * .xlsx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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