我找不到event.source对象的任何的相关详细资料,所以我想知道是否有可能访问修改范围的前值,所以我可以与用于验证的范围内的旧值比较范围的新值。
谢谢你的帮助。
OnEdit(事件)
function onEdit(event)
/* Default onEdit Event function */
{
var ssa = SpreadsheetApp.getActiveSpreadsheet();
var ss = event.source.getActiveSheet();
var r = event.source.getActiveRange();
...
-编辑看来这是现在有可能,请带看波纹管的链接和评论。
详细信息可在文档这里 。
但以前的值不可用的事件。 这里有一个增强请求对此开了。 你应该“明星”,随时记录更新和那种投赞成票的。
现在,为了“解决方法”。 所有这些都基于这样的事实,你将不得不救自己别的地方的原始数据。 你可以有一个反光镜电子表格或表,并在任何onEdit
发生在原来的你可以去照镜子,让旧值。 这是一个稍微复杂一点似乎比,因为你也不得不更新通过脚本镜电子表格,但不能在电子表格中的所有事件触发onEdit
事件,如插入行。 所以,你的脚本必须要格外聪明跟上这些,这取决于你的使用情况,可能甚至是不可能的。
你可以利用ScriptDb中的存储信息onLoad()
然后读回onEdit()
每当有一个编辑,就可以调用onLoad()
又再次刷新单元格值的数据库或只需更换数据库的相关信息。
加入notonEdit()
来触发的资源FromSpreadsheet> onEdit()事件>您所有的触发菜单。
下面是代码:
function onLoad() {
var db = ScriptDb.getMyDb()
//get array of the sheet range that has something in it
var sheet = SpreadsheetApp.getActiveSheet()
var lastrow = sheet.getLastRow()
var lastcolumn = sheet.getLastColumn()
var subsheet = sheet.getRange(1, 1, lastrow, lastcolumn)
var values = subsheet.getValues()
//write that array into the ScriptDB of the project
for (i=1; i<=lastrow; i++){
for (j=1; j<=lastcolumn; j++){
var object = {type: "onEditfudge", row: i, column:j, value:values[i-1][j-1]}
db.save(object)
Logger.log(object) //log it to check its correct..
}
}
}
function BeforeonEdit(){
db = ScriptDb.getMyDb()
var newrange = SpreadsheetApp.getActiveRange()
//get 'old value'
var dbentry = db.query({type: "onEditfudge", row:newrange.getRow(),column:newrange.getColumn()}).next()
var oldvalue = dbentry.value
//overwrite the 'old value' with the 'new value' for the next onEdit() event
dbentry.value = newrange.getValue()
db.save(dbentry)
//return the old value to do something with in the calling function
return oldvalue
}
function notonEdit(){
//show new and old value
Browser.msgBox("Old value is: " + BeforeonEdit() + ". New Value is: " + SpreadsheetApp.getActiveRange().getValue())
}
文章来源: onEdit Event object access to previous value of a cell that has been modified?