【问题标题】:I just want my Goggle Sheets loop to stop when a specific cell = Total我只希望我的 Google 表格循环在特定单元格 = 总计时停止
【发布时间】:2022-11-09 05:56:07
【问题描述】:

我目前正在使用 Google 表格运行 USFL Fantasy 足球联赛,这让我发疯了。基本上我有一个IMPORTXML 用于获取我的统计数据的网站,但统计数据都是垂直的,所以我将上面的代码设置为TRANSPOSE 连续每个玩家。目前,我必须为每个玩家运行我的代码,但我希望它在"Total" 位于顶部单元格中时自动停止,因为我不需要行中的总统计数据。我真的不明白为什么当我将WHILE 设置为"cc_total" 变量为“!=”(不等于)“总计”时,它会在单元格DOES == "Total" 时继续运行。我没有得到什么?

function TRANSPOSE1() {
  var spreadsheet = SpreadsheetApp.getActive();
  do {
    spreadsheet.getRange('F2').activate();
    spreadsheet.getCurrentCell().setFormula('=IFERROR(TRANSPOSE(D18:D31),FALSE)');
    var currentCell = spreadsheet.getCurrentCell();
    spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.NEXT).activate();
    currentCell.activateAsCurrentCell();
    spreadsheet.getRange('F5').activate();
    spreadsheet.getRange('F2:S2').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
    spreadsheet.getRange('F5:S5').insertCells(SpreadsheetApp.Dimension.ROWS);
    spreadsheet.getRange('D18:D31').activate();
    spreadsheet.getRange('D18:D31').deleteCells(SpreadsheetApp.Dimension.ROWS);
    spreadsheet.getRange('F3').activate();
    var cc_total = spreadsheet.getCurrentCell()
    cc_total.activate();
  } while (cc_total != "Total");
};

【问题讨论】:

    标签: google-apps-script google-sheets transpose do-while macro-recorder


    【解决方案1】:

    目前 cc_total 正在获取一个范围而不是一个值

    所以你的循环没有按照你想象的方式工作

    var cc_total = spreadsheet.getCurrentCell() 替换为var cc_total = spreadsheet.getCurrentCell().getDisplayValue() 并将cc_total.activate(); 替换为spreadsheet.getCurrentCell().activate()

    【讨论】:

    • 而已!我有一种感觉,我错过了一些我不知道它是什么的东西,但 getDisplayValue 绝对是我想要的。一直都是这样吗?它以前不只是 getValue 吗?
    • 没有对您的问题进行任何编辑的历史记录,因此它仍然是您所写的。
    猜你喜欢
    • 2016-04-01
    • 2020-12-09
    • 2014-03-21
    • 2015-10-15
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    相关资源
    最近更新 更多