转换 mimeType:从应用程序/八度流到文本/csv - 谷歌脚本



我想从电子邮件中获取csv文件附件(msg_att(,获取数据,然后将其复制到电子表格文件。我正在研究谷歌脚本。 到目前为止,我所做的如下:

var newFile=DriveApp.createFile(msg_att).setName("GDriveData")
var attachmentID = newFile.getId()
var date = new Date();
var files = DriveApp.getFileById(attachmentID)
var xlsFile = files.getMimeType();  
Logger.log(xlsFile);
var newSheet =  Drive.Files.copy({}, attachmentID, {convert: true});

不幸的是,最后一行返回以下错误:

对 drive.files.copy 的 API 调用失败,出现错误:不支持请求的转换

MimeType是application/octate-stream

我调查了这个问题,我看到 mimeType 应该是"text/csv",因为我想获取 csv 附件。

有没有办法将 mimeType:从应用程序/八度流转换为文本/csv ?

我试过这个,但它不起作用:

var newFile=DriveApp.createFile(msg_att).setName("GDriveData").setMimeType('text/csv')

我也试过这个,但没有用:

var newFile = DriveApp.createFile('name',msg_att,'text/csv');

假设msg_att实际上是一个CSV,你可以在createFile()中设置MIME类型:createFile(name, content, mimeType)

最新更新