[英]Appending a Google Sheet file with newest Google Drive .csv file located in a specific folder
I've got a plugin that works with Zapier to send a.csv (can have different format) file to a specific Google Drive folder with some order data from the day before, every 24h.我有一个与 Zapier 配合使用的插件,每 24 小时将 a.csv (可以有不同的格式)文件发送到特定的 Google Drive 文件夹,其中包含前一天的一些订单数据。
I would love to append my Google Sheet file using AppsScript with the data from the newest file in the folder.我很想使用 AppsScript 使用文件夹中最新文件中的数据来 append 我的 Google 表格文件。
Is such solution even possible?这样的解决方案甚至可能吗? What sources would you recommend to try to write a code like this?
您会推荐哪些资源来尝试编写这样的代码?
(I know I could do this with Zapier but that would require ridiculous plan to have it done:)) (我知道我可以用 Zapier 做到这一点,但这需要荒谬的计划才能完成:))
Thanks a lot.非常感谢。
Something like this should help:这样的事情应该会有所帮助:
It gets the latest csv file in a folder and loads it in to the active sheet.它在文件夹中获取最新的 csv 文件并将其加载到活动工作表中。
function getTheLatestFile() {
const folder = DriveApp.getFolderById("folderid");
const files = folder.getFilesByType(MimeType.CSV);
const arr = [];
while(files.hasNext) {
let file = files.next();
arr.push({name:file.getName(),id:file.getId(),date:file.getDateCreated()});
}
arr.sort((a,b)=> {
return new Date(b.date).valueOf() - new Date(a.date).valueOf();
})
let vs = Utilities.parseCsv(DriveApp.getFileById(arr[0].id),getBlob().getDataAsString());
let sh = SpreadsheetApp.getActiveSheet();
sh.clearContents();
sh.getRange(1,1,vs.length, vs[0].length).setValues(vs);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.