我想自动从Google电子表格创建csv文件(单击按钮后)。 但我不想导出整个电子表格,只需要几列。 我怎么能这样做?
例如。电子表格有8列,我想将前三个导出到csv,其值如:" column1 value; column2值; column3值; column1值; column2值; ......"
谢谢
答案 0 :(得分:0)
这里你去:(你需要发布它,如果你想让它工作)它将导出你正在做的选择
function onOpen() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "make CSV",
functionName : "myFunction"
}];
spreadsheet.addMenu("Script Center Menu", entries);
};
function myFunction() {
var a1 = SpreadsheetApp.getActiveRange().getA1Notation();
var url = ScriptApp.getService().getUrl()+"?ref="+a1+"&sheet="+SpreadsheetApp.getActiveSheet().getName()+"&ssid="+SpreadsheetApp.getActive().getId();
var vals = SpreadsheetApp.getActiveRange().getValues();
var html = "here the download Link <a href='"+url+"' >"+url+"</a>";
//SpreadsheetApp.getActive().show(HtmlService.createHtmlOutput(html)); // ol sheet style
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(html), 'download box'); // new sheet style
}
function doGet(e){
var ref = e.parameter.ref;
var sheet = e.parameter.sheet;
var ssid = e.parameter.ssid;
var out = ContentService.createTextOutput(SpreadsheetApp.openById(ssid).getSheetByName(sheet).getRange(ref).getValues().join("\n")).downloadAsFile("out.csv");
return out;
}