如果所有列都为空则隐藏行 Google Sheets App Script
Hide rows if all columns are blank Google Sheets App Script
我正在尝试获取一个自动脚本来检查 "D9" 右侧的列是否为空白,如果全部为空白,则隐藏该行。我的想法是使用 for 循环进行迭代并逐行进行检查,因此将范围内的 Row 参数替换为 'i' 但似乎出于某种原因,如果我使用 A1notation 它可以工作但不能使用 'row' 和 'column' 参数。我几天前才开始弄乱这个,所以我确定我做错了什么,所以如果你能指出我正确的方向并指出为什么这不起作用,那就太好了 :)
所以这有效:
function SelectLastColumn() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange("D9").activate();
var currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection()
.getNextDataRange(SpreadsheetApp.Direction.NEXT).activate();
currentCell.activateAsCurrentCell();
这不是:
function SelectLastColumn() { var spreadsheet =
SpreadsheetApp.getActive(); spreadsheet.getRange(9,4).activate(); var
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection()
.getNextDataRange(SpreadsheetApp.Direction.NEXT).activate();
currentCell.activateAsCurrentCell();
关于上面脚本有效而下面脚本无效的原因,这个答案怎么样?在您的脚本中,spreadsheet
of var spreadsheet = SpreadsheetApp.getActive();
是作为对象的电子表格。这种情况使用getRange()
时,需要注意以下几点。
- 当
getRange()
被a1Notation使用时,它可以用于Spreadsheet和Sheet.
- 行列使用
getRange()
时,只能用于Sheet.
从以上几点来看,对于你的脚本,当你的脚本修改如下时,你的两个脚本都可以使用。
发件人:
var spreadsheet = SpreadsheetApp.getActive();
收件人:
var spreadsheet = SpreadsheetApp.getActiveSheet();
参考:
如果我误解了你的问题,我很抱歉。
我正在尝试获取一个自动脚本来检查 "D9" 右侧的列是否为空白,如果全部为空白,则隐藏该行。我的想法是使用 for 循环进行迭代并逐行进行检查,因此将范围内的 Row 参数替换为 'i' 但似乎出于某种原因,如果我使用 A1notation 它可以工作但不能使用 'row' 和 'column' 参数。我几天前才开始弄乱这个,所以我确定我做错了什么,所以如果你能指出我正确的方向并指出为什么这不起作用,那就太好了 :)
所以这有效:
function SelectLastColumn() { var spreadsheet = SpreadsheetApp.getActive(); spreadsheet.getRange("D9").activate(); var currentCell = spreadsheet.getCurrentCell(); spreadsheet.getSelection() .getNextDataRange(SpreadsheetApp.Direction.NEXT).activate(); currentCell.activateAsCurrentCell();
这不是:
function SelectLastColumn() { var spreadsheet = SpreadsheetApp.getActive(); spreadsheet.getRange(9,4).activate(); var currentCell = spreadsheet.getCurrentCell(); spreadsheet.getSelection() .getNextDataRange(SpreadsheetApp.Direction.NEXT).activate(); currentCell.activateAsCurrentCell();
关于上面脚本有效而下面脚本无效的原因,这个答案怎么样?在您的脚本中,spreadsheet
of var spreadsheet = SpreadsheetApp.getActive();
是作为对象的电子表格。这种情况使用getRange()
时,需要注意以下几点。
- 当
getRange()
被a1Notation使用时,它可以用于Spreadsheet和Sheet. - 行列使用
getRange()
时,只能用于Sheet.
从以上几点来看,对于你的脚本,当你的脚本修改如下时,你的两个脚本都可以使用。
发件人:
var spreadsheet = SpreadsheetApp.getActive();
收件人:
var spreadsheet = SpreadsheetApp.getActiveSheet();
参考:
如果我误解了你的问题,我很抱歉。