简体   繁体   English

使用位于特定文件夹中的最新 Google Drive.csv 文件附加 Google Sheet 文件

[英]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.

相关问题 搜索特定google驱动器文件夹中的最新文件 - Searching for the newest file in a specific google drive folder 在特定的驱动器文件夹中引用最新的Google工作表 - Reference newest google sheet in specific drive folder 将 .csv 文件从谷歌驱动器文件夹导入现有的谷歌工作表 - importing .csv file from google drive folder to an existing google sheet 获取 Google Drive 文件夹中的最新文件 - Get the Newest File in a Google Drive Folder 自动将 Google Drive 文件夹中最新 CSV 文件中的数据粘贴到 Google Sheet - Automatically Paste Data from Latest CSV File in Google Drive Folder to Google Sheet 尝试从 Google 表格中的 URL 将文件的副本保存到特定的 Google Drive 文件夹 - Trying to save a copy of a file to specific Google Drive folder, from URLs in a Google Sheet 如何使用共享的Google驱动器文件夹上的Google App脚本删除特定文件夹中的特定类型的文件(CSV文件) - How do I delete a specific type of file (CSV files) within a specific folder with google app script on a shared google drive folder 在特定的驱动器文件夹中创建一个新的Google表格 - Create a new Google Sheet in a specific drive folder 将Google云端硬盘文件夹中的文件和网址列表放入表格中 - Getting a list of file and url in a Google Drive folder into a sheet 将工作表从 SpreadSheet 文件复制到 Google 云端硬盘文件夹 - Copy a sheet from a SpreadSheet file to a Google Drive folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM