如果你想使它这样,每当有人提出在“100”的值,它会清除整个表的内容,那么你可以这样做:
function onEdit(e) {
var ss = SpreadsheetApp.getActive() //gets the active spreadsheet
var sheet = SpreadsheetApp.getActiveSheet() //gets the active sheet
var cell = ss.getActiveRange() //gets the active cell
var cellContent = cell.getValue() //gets the value of the active cell
if(cellContent === 100) {
sheet.clearContents() //clears the values of the entire active sheet
}
}
如果你想让这个每当有人编辑的单元格,使得其值“100”,代码清除只有细胞,那么这样做:
function onEdit(e) {
var ss = SpreadsheetApp.getActive()
var sheet = SpreadsheetApp.getActiveSheet()
var cell = ss.getActiveRange()
var cellContent = cell.getValue()
if(cellContent === 100) {
cell.setValue("") //clears the value of the active cell
}
}
当然,在后者,由于轻微的滞后谷歌脚本,如果有人迅速投入100英寸每个细胞他们可以,然后一些值为“100”的细胞将停留在那里,但如果这个人像正常的人而不是垃圾邮件发送者一样把值放入,那么这个代码就可以工作。
另外,如果你想这样,如果某个单元格的值(即:A1),使其等于“100”的剧本清除整个工作表,这样做:
function onEdit(e) {
var ss = SpreadsheetApp.getActive()
var sheet = SpreadsheetApp.getActiveSheet()
var cell = sheet.getRange('A1')
var cellContent = cell.getValue()
if(cellContent === 100) {
sheet.clearContents()
}
}
希望我能帮上忙!
如果解决了[此问题3496](https://code.google.com/p/google-apps-script-issues/issues/detail?id=3496),您可以检查哪个单元格触发了onEdit,并且当它不是你想要的时候,什么都不会返回......不幸的是,它不是...... – 2014-10-05 21:39:02
看起来像这个问题在2014年10月7日关闭 – 2014-10-07 15:33:26
事实上,我今天早上收到一条消息,告诉问题已修复。感谢您指出了这一点 :-) – 2014-10-07 15:43:19