Apps 脚本驱动应用服务 - 创建 Google 类型 - Mime 类型的文件

2024-03-28

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

createFile(name, content, mimeType)

文档在这里:createFile Google DriveApp 服务 https://developers.google.com/apps-script/reference/drive/drive-app#createFile%28String,String,String%29

该示例显示了mimeTypeMimeType.HTML 的设置。

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

我可以输入MimeType.并获取 MimeTypes 列表,其中之一是GOOGLE_DOCS。所以我进入了MimeType.GOOGLE_DOCS。但我收到执行错误,指出其中一个参数无效。如果我输入 Mime 类型“text/plain”,则不会出现错误。

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

如果我输入 Mime 类型“GOOGLE_DOCS”作为文本,它会创建一个文件,但它会创建一个文件类型为application/octet-stream.

如果我使用 MimeType 为MimeType.HTML,我没有收到错误,并且可以从我的 Google 云端硬盘查看该文件。


您可以使用DocumentApp.create('File_Name')创建一个文件类型GOOGLE_DOCS。 DocumentApp 服务允许创建和操作 Google 文档。想要了解更多详情,你可以查看参考资料。

参考:

  • https://developers.google.com/apps-script/reference/document/document-app https://developers.google.com/apps-script/reference/document/document-app

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

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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Apps 脚本驱动应用服务 - 创建 Google 类型 - Mime 类型的文件 的相关文章

随机推荐