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);
}