尝试以 CSV 格式下载 Google 表格,以保留时间戳的格式
我可以使用以下气体脚本来做到这一点。
但它只下载第一张。
我希望能够声明要下载的表格
如何做到这一点?
煤气
function autoDownload() {
var html = HtmlService.createHtmlOutputFromFile('download');
SpreadsheetApp.getUi().showModalDialog(html, 'CSV download dialog');
Utilities.sleep(9000);
}
function saveAsCSV() {
let ss = SpreadsheetApp.getActiveSpreadsheet(),
ssname = "sumApp-Headers",
sheet = ss.getSheetByName("Elements");
var folder ="1KivXXXXfW3" // DriveApp.getFileById(ss.getId()).getParents().next();
var fileName = ssname + ".csv";
var params = ss.getId() + "/export?exportFormat=csv&format=csv";
var url = "https://docs.google.com/spreadsheets/d/" + params;
var token = ScriptApp.getOAuthToken();
console.log(url)
var response = UrlFetchApp.fetch(url + sheet.getSheetId(), {
headers: {
'Authorization': 'Bearer ' + token
}
});
url = DriveApp.getFolderById(folder)
.createFile(ssname, response, MimeType.CSV)
.getDownloadUrl();
//.replace("?e=download&gd=true","");
return url;
}
html
<!DOCTYPE html>
<html>
<body>
Auto Download CSV ... please wait
</body>
<script>
function executeDownload(url) {
window.location.href = url;
}
window.onload=function() {
google.script.run
.withSuccessHandler(executeDownload)
.saveAsCSV();
window.setTimeout(function(){google.script.host.close()},9000);
}
</script>
</html>
关于
I want to be able to declare the sheet to download
,作为一个简单的修改,下面的修改怎么样?
var response = UrlFetchApp.fetch(url + sheet.getSheetId(), {
var response = UrlFetchApp.fetch(url + "&gid=" + sheet.getSheetId(), {
sheet = ss.getSheetByName("Elements");
给出的表格。