使用应用程序脚本将csv数据导入到Google表格中 [英] Import csv data into google sheets using apps script

查看:54
本文介绍了使用应用程序脚本将csv数据导入到Google表格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Apps脚本将csv文件导入Google表格.我想将要读取的csv文件添加到最后一行之后的现有选项卡"csv_data"中.有人能帮我吗?我是开始使用应用程序脚本的用户.预先感谢您的帮助!GJM

I would like to import a csv file into Google Sheets using Apps Script. I would like to add the csv file to be read to the existing tab "csv_data" after the last line. Can someone help me? I am a starting apps script user. Thank you in advance for your help! GJM

推荐答案

有一种有用的方法,称为

There is a useful method, called Utilities.parseCsv()

如果您的csv文件位于Google驱动器上,则可以导入和附加该文件,例如通过将具有以下内容的绑定脚本附加到电子表格,

If your csv file is located on your Google drive, you can import and append it e.g. by attaching to your spreadsheet a bound script with the following content:

function appendCSV() {  
  var file = DriveApp.getFilesByName("PASTE HERE THE NAME OF YOUR CSV FILE INCLUDING EXTENSION").next();
  var csvData = Utilities.parseCsv(file.getBlob().getDataAsString(),'SPECIFY HERE THE DELIMITER (OPTIONAL)');
  var sheet = SpreadsheetApp.getActiveSheet();
  var lastRow=sheet.getLastRow();
  sheet.getRange(lastRow, 1, csvData.length, csvData[0].length).setValues(csvData);  
}

这篇关于使用应用程序脚本将csv数据导入到Google表格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆