Google AppScript检查单元格值和删除列
我目前有一个项目,必须循环并检查3个不同的单元格值。如果值包含#value1,则应该删除列。我不确定我在做什么错。我不断遇到错误,并且列永远不会删除。另外,我会收到我无法弄清楚的循环错误。
function scoreToGrade() {
var cellsChecked = ['AF2', 'AG2', 'AH2'];
var sheet = SpreadsheetApp.getActiveSheet();
for (var i = 0; i < cellsChecked.length; i++) {
var value = SpreadsheetApp.getActiveSheet()
.getRange(cellsChecked[i])
.getDisplayValues();
console.log(value);
if (value == '#VALUE!') {
// do something
console.log('Not blank ' + value);
sheet.deleteColumn(cellsChecked + 1);
} else {
// do something else
console.log('is another value ' + value);
}
}
}
日志如下
3:41:23 PM Notice Execution started
3:41:23 PM Info [ [ 'TR' ] ]
3:41:23 PM Info is BlankTR
3:41:23 PM Info [ [ 'F' ] ]
3:41:23 PM Info is BlankF
3:41:23 PM Info [ [ '#VALUE!' ] ]
3:41:23 PM Info Not blank #VALUE!
3:41:23 PM Error
Exception: Cannot convert 'AF2,AG2,AH21' to int.
scoreToGrade @ Code.gs:115
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试以下操作:
Try this:
您的错误似乎是在您使用的线路中删除
要将单元格数组传递到此函数的列而不是该方法期望的单个单元格。尝试传递特定数组项目,类似于您在脚本中获得单元格值时所做的类似。
参考:
问题自发布以来发生了变化
Your error appears to be in the line you are using to delete the columns
You are passing an array of cells to this function instead of the single cell that the method expects. Try passing in a specific array item similar to what you did when getting the value of the cell earlier in your script.
Reference: https://developers.google.com/apps-script/reference/spreadsheet/sheet#deletecolumncolumnposition
Question has changed since posting this reply