【发布时间】:2020-01-06 03:20:12
【问题描述】:
以前的 StackOverflow 帖子报告说 UrlFetchApp 在超过一分钟的运行时间后终止。这发生在我身上并且正在影响我的程序。该程序自动将电子表格转换为 Excel 文件作为备份和保存数据。电子表格有很多数据,所以现在超时。我对该程序的替代解决方案是什么?我的 google 电子表格不是很大,也没有达到 google sheet 的最大阈值,因此不需要清除数据的难度。
function downloadSpreadSheet(){
var spreadsheet_id = "INSERT_ID_HERE"; //spreadsheet_id is the id of the google sheet, found in URL
var ss = SpreadsheetApp.openById(spreadsheet_id);
var now = new Date();
var driveFolder = 'Dispatch Backup'; //driveFolder is the name of the destination folder on Google Drive
var newFilename = 'Exported ' + (now.getMonth()+1) + '-' + now.getDate() + "-" + now.getYear(); //newFilename is the name of the .xlsx file to be written out
var folder = DriveApp.getFoldersByName(driveFolder); //folder is a collection of all folders in the user's Drive with that name
var params = { //params are the parameters used to grant authority to copy and save the new file
method : "get",
headers : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
muteHttpExceptions: true
};
//url is html around the spreadsheet ID that converts the sheet into Excel format
var url = "https://docs.google.com/feeds/download/spreadsheets/Export?key="+spreadsheet_id+"&exportFormat=xlsx";
var doc = UrlFetchApp.fetch(url, params).getBlob(); //TIMES OUT HERE //doc contains the converted sheet data
//finds the location of driveFolder or creates one if not present
if (folder.hasNext()) {
folder = folder.next();
} else {
folder = DriveApp.createFolder(driveFolder);
}
//Creates a file in the root of the user's Drive from a given Blob of arbitrary data.
file= folder.createFile(doc);
//Sets the name of the File.
if (newFilename != "")
file.setName(newFilename)
}
感谢任何帮助或建议。谢谢。
【问题讨论】:
-
尝试使用提要网址的其他方法。有关详细信息,请查看 Mogsdad 回复 stackoverflow.com/q/27277058/1595451
-
感谢您提供。我已经尝试过他的代码,但仍然失败。他在他的脚本中使用了 UrlFetchApp,所以我再次遇到超时错误也就不足为奇了。