我正在构建一个Google脚本来与云端硬盘和表格进行互动。运行下面的代码时,执行
时出错" log.getActiveSheet()。getRange(log.getLastRow(),2)。setValue = date;"
表示"对象不允许添加或更改属性。"我无法弄清楚为什么。
有没有人有任何见解?
function setUp() {
Logger.log("Starting setUp()");
var user = Session.getActiveUser();
var files = DriveApp.getFilesByName("ChangeAlert_Log");
Logger.log(files.hasNext());
var log;
if(files.hasNext() == false){
Logger.log("creating log file now...");
log = SpreadsheetApp.create("ChangeAlert_Log");
log.getActiveSheet().getRange(1, 1).setValue("file_names");
log.getActiveSheet().getRange(1, 2).setValue("file_dates");
return log;
} else{
Logger.log("Found Log...trying to open");
var logFile = files.next();
var url = logFile.getUrl()
log = SpreadsheetApp.openByUrl(url);
log.addEditor(user);
Logger.log("returning setUp()");
return log;
}
}
function IDfiles(){
Logger.log("running IDfiles()");
var log = setUp()
var user = Session.getActiveUser();
var user_files = DriveApp.getFiles(); //returns a FileIterator Object
var i = 0;
var file;
while(user_files.hasNext()){
file = user_files.next();
if(file.isStarred()){
var date = file.getLastUpdated();
Logger.log("Date: " + date);
//file_dates[i] = date;
log.getActiveSheet().getRange(log.getLastRow(),2).setValue = date;
var fileName = file.getName();
Logger.log("File: " + fileName);
log.getActiveSheet().getRange(log.getLastRow(), 1).setValue = fileName;
//file_names[i] = fileName;
i++;
Logger.log("i= " + i);
}
}
Logger.log("returning IDfiles()");
return;
答案 0 :(得分:0)
不是从函数中返回日志对象,而是获取新创建的电子表格ID并返回。
var log = SpreadsheetApp.create("some log");
return log.getId();
然后一旦返回,再次通过ID获取工作表。