我正在将以下脚本作为自己的.gs文件运行
/**
* TITLE:
* Hide a row if a value is inputted.
*/
//**GLOBALS**
// Sheet the data is on.
var SHEET = "Norm Adam";
// The value that will cause the row to hide.
var VALUE = "Yes";
// The column we will be using
var COLUMN_NUMBER = 11
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeSheet = ss.getActiveSheet();
//Ensure on correct sheet.
if(SHEET == activeSheet.getName()){
var cell = ss.getActiveCell()
var cellValue = cell.getValue();
//Ensure we are looking at the correct column.
if(cell.getColumn() == COLUMN_NUMBER){
//If the cell matched the value we require,hide the row.
if(cellValue == VALUE){
activeSheet.hideRow(cell);
};
};
};
}
它在电脑浏览器上运行良好,但在iOS设备上,它无法通过谷歌表单应用程序运行,实际上我甚至无法通过safari获得可编辑内容。我读到只有onEdit功能可以在移动设备上工作,所以我认为这应该可以工作。这个谜题还有另一块吗?谢谢Mike
(剧本创作的功劳归于:https://yagisanatode.com/2018/05/26/how-to-hide-a-row-based-on-a-cell-value-in-google-sheets-with-filter-or-google-apps-script/(
脚本V2:我在下面评论了这在iOS中仍然不起作用。我想它越简单就越有可能工作?
function onEdit(e) {
if (e.range.getColumn() == 11 && e.value == 'Yes') {
e.range.getSheet().hideRows(e.range.getRow());
}
}
getActive
调用,尤其是ss.getActiveCell()
应避免在移动应用程序上调用。考虑像e.range
这样的替代方案,从事件对象中获取编辑后的范围。