Apps Script Drive App Service-创建Google类型的文件-Mime类型 [英] Apps Script Drive App Service - Create a file of Google Type - Mime Type

查看:42
本文介绍了Apps Script Drive App Service-创建Google类型的文件-Mime类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 DriveApp Folder 类的 .createFile 方法.这是语法:

I'm using the .createFile method of the DriveApp Folder class. This is the syntax:

createFile(name, content, mimeType)

文档在这里: createFile Google DriveApp服务

该示例显示了MimeType.HTML的 mimeType 设置.

The example shows a mimeType setting of MimeType.HTML.

// Create an HTML file with the content "Hello, world!"
 DriveApp.createFile('New HTML File', '<b>Hello, world!</b>', MimeType.HTML);

我可以输入 MimeType.并获取MimeType的列表,其中一个是 GOOGLE_DOCS .所以我输入了 MimeType.GOOGLE_DOCS .但是我收到一条执行错误,指出其中一个参数无效.如果我输入文字/纯文字"的Mime类型,则不会出现错误.

I can type in MimeType. and get a list of MimeTypes, one of them being GOOGLE_DOCS. So I entered MimeType.GOOGLE_DOCS. But I'm getting an execution error stating that one of the arguments is invalid. If I type in a Mime Type of 'text/plain', I get no error.

如何创建文档类型为Google Type的文件?

How do I create a file with the document type of a Google Type?

如果我将"MIME类型"输入为"GOOGLE_DOCS"作为文本,它将创建一个文件,但是会创建一个文件类型为 application/octet-stream 的文件.

If I enter a Mime Type of 'GOOGLE_DOCS' as text, it creates a file, but it creates a file with a file type of application/octet-stream.

如果我使用MimeType为 MimeType.HTML 的MimeType,则不会出现错误,并且可以从Google云端硬盘中查看该文件.

If I use a MimeType of MimeType.HTML, I don't get an error, and the file is viewable from my Google Drive.

推荐答案

您可以使用 DocumentApp.create('File_Name')创建 GOOGLE_DOCS 的文件类型.DocumentApp服务允许创建和处理Google文档.有关更多详细信息,请检查参考.

You can use DocumentApp.create('File_Name') to create a fileType of GOOGLE_DOCS. DocumentApp service allows to create and manipulate Google Documents. For more details, you may check the reference.

参考文献:

为了将最近创建的文档放置在文件夹中,可以使用 DriveApp .这是示例代码.

In order to place the recently create Document in a Folder, you may use DriveApp. Here is a sample code.

function createandPlaceInFolder(){
  //Create the document
  var doc = DocumentApp.create('My new file');
  //get it as a drive file
  var file = DriveApp.getFileById(doc.getId());
  //get the target folder
  var targetFolder  = DriveApp.getFolderById('MY_FOLDER_ID');//Change it to the folder_Id
  //place the file in target folder
  targetFolder.addFile(file);
}

这篇关于Apps Script Drive App Service-创建Google类型的文件-Mime类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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