Google Apps Script - convert to CSV

淺唱寂寞╮ 提交于 2019-11-28 06:18:25

问题


I would like to export a Google Sheet to CSV on form submit. I have searched but the only thing similar does not separate it into different columns once I have converted it: Export spreadsheet or CSV text file from Google Drive Forms using script?

It's a simple sheet with 8 columns only.

Any help appreciated


回答1:


Once you get the values of a spreadsheet range, you'll end up with a two dimensional array. So to convert it, you'll have to construct a string that joins array array cell elements with a comma and join the rows with a new-line ("\n");

Haven't tested this, but should be something like this.

var range = someSheet.getRange("A2:B" + someSheet.getLastRow());
var vals = range.getValues();
//let's pretend vals is as below
var vals = [["A2","B2"], ["A3", "B3"]];
var csvString = vals.join("\n");
DriveApp.createFile("mycsv.csv", csvString);


来源:https://stackoverflow.com/questions/28327109/google-apps-script-convert-to-csv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!