滚动单元显示在屏幕顶部 [英] Scroll cell is displayed at top of screen

查看:65
本文介绍了滚动单元显示在屏幕顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在共享的Google表格中,用户输入每个工作的小时数作为预测工具.这些作业分为3组,因此我想拥有一个脚本,以便用户可以轻松滚动至其相关部分.

In a shared Google Sheet, users enter their hours against each job, as a forecasting tool. The jobs are in 3 groups, so I want to have a script so users can easily scroll to their relevant section.

我写了一个脚本,它可以正确执行.它会在A列中找到标题字符串,返回行号,然后激活包含标题的单元格.

I have written a script, and it executes correctly. It finds the heading string in column A, returns the row number, and then activates the cell containing the heading.

// global variables
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var err_msg = "Sorry, can't find link to "
var lastcell = sheet.getRange(sheet.getLastRow(), 1, 1, 1); //row, column, numRows, numColumns


// search in column A:A for the headings, returns row number
function findInColumn(data) {

  var sheet  = SpreadsheetApp.getActiveSpreadsheet();
  var values = sheet.getRange('A1:A' + sheet.getLastRow()).getValues();    // column + ":" + column like A:A

  //var values = column.getValues(); 
  var row = 0;

  while ( values[row] && values[row][0] !== data ) {
    row++;
  }

  if (values[row][0] === data) 
    return row+1;
  else 
    return -1;

}


function jumpTo_LargeScaleHybrid() {

  var data = "LARGE SCALE / HYBRID";
  var rownum = findInColumn(data);

  var range = sheet.getRange(rownum, 1, 1, 1); //row, column, numRows, numColumns

  if (rownum && -1) {
    sheet.setActiveRange(range);
  }
  else {
    Browser.msgBox("Sorry, can't find link to 'LARGE SCALE / HYBRID'. Someone must have changed the target name.");
  }
}

但是,所选单元格位于屏幕的底部,而我希望它位于顶部.

However, the selected cell is at the bottom of the screen whereas I'd like it at the top.

如果起始位置在作业列表的底部,那么它将起作用.但是,如果起始位置位于大多数用户开始的顶部,则不会.

If the starting position is at the bottom of the list of jobs, then it works. But not if the starting position is at the top, where most users begin.

推荐答案

我已经找到了使用Flush命令解决该问题的方法.

I've found a workaround for my issue, using the Flush command.

我能够选择/激活列中的最后一个单元格,执行.flush命令,然后(有效)向上滚动至所需的单元格

I was able to select/activate the last cell in the column, execute the .flush command, and then (effectively) scroll up to the cell I want

var lastcell = sheet.getRange(sheet.getLastRow(), 1, 1, 1)
sheet.setActiveRange(lastcell);
SpreadsheetApp.flush();
sheet.setActiveRange(range);

这篇关于滚动单元显示在屏幕顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆