onLoad()
정보를 저장하기 위해 ScriptDB를 사용하고 onEdit()
을 다시 읽을 수 있습니다. 편집 할 때마다 onLoad()
을 다시 호출하여 셀 값의 데이터베이스를 다시 새로 고치거나 데이터베이스의 관련 정보를 바꿀 수 있습니다.
리소스> 모든 트리거 메뉴에서 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())
}
감사 : 여기서
코드이다. 나는 향상 요청을 "봤다". 나는이 문서에 대한 링크를 알고 있었지만, 이것 만이 아니었을지라도! ;-) – VanacK[Issue # 47 on issue 200] (https://code.google.com/p/google-apps-script-issues/issues/detail?id=200#c47)에 따르면 동일한 문제 Henrique에 의해 참조 된, 이제는 onEdit (e) ... e.oldValue를 사용하여 이전 값에 접근 할 수 있습니다. –
e.oldValue 사용하기 나는 '정의되지 않음'을 얻고 있습니다. 제발 도와주세요 –