【发布时间】:2019-12-04 15:12:06
【问题描述】:
我想从电子邮件中获取 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: 从 application/octate-stream 转换为 text/csv 吗?
我试过了,但它不起作用:
var newFile=DriveApp.createFile(msg_att).setName("GDriveData").setMimeType('text/csv')
我也试过了,还是不行:
var newFile = DriveApp.createFile('name',msg_att,'text/csv');
【问题讨论】:
-
当
Logger.log(msg_att.getDataAsString())和Logger.log(newFile.getBlob().getDataAsString())放在var newFile=DriveApp.createFile(msg_att).setName("GDriveData")之后运行脚本,你会在日志中看到什么值?
标签: javascript google-apps-script google-sheets