简体   繁体   English

根据单元格值滚动一行到屏幕顶部:Google Sheet Script

[英]Scroll a row to the top of the screen based on cell value: Google Sheet Script

I have a google spreadsheet.我有一个谷歌电子表格。 Column M are numbers (number of days left), ranging from -33 to 35. I'm a newbie to script, and really have no idea how to implement the following: M 列是数字(剩余天数),范围从 -33 到 35。我是脚本新手,真的不知道如何实现以下内容:

a) When opening the spreadsheet, the row which Column M has a value of 1, will scroll up automatically to the very top of the screen. a) 打开电子表格时,M 列值为 1 的行将自动向上滚动到屏幕的最顶部。

b) When several rows are having a value of 1 in the M column, all rows with 1 will scroll to the top altogether, starting with the row with the first 1, followed by the rest of ones. b) 当 M 列中有几行的值为 1 时,所有带 1 的行将一起滚动到顶部,从第一个 1 的行开始,然后是一个的 rest。

I hope you can help me.我希望你能帮助我。 Thanks.谢谢。

enter image description here在此处输入图像描述

The function goes to sh.getRange(sh.getMaxRows()) and I activate() it there and the I jump back to the sh.getRange(1,13,sh.getLastRow(),1).getValues().flat().indexOf(1) ) + 1 which is the row number of the number 1 in column M or 13. function 转到sh.getRange(sh.getMaxRows())并在那里激活它,然后我跳回到sh.getRange(1,13,sh.getLastRow(),1).getValues().flat().indexOf(1) ) + 1是第 M 列或第 13 列中数字 1 的行号。

function scrollToOne() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  sh.getRange(sh.getMaxRows(),1).activate();
  SpreadsheetApp.flush();
  const row = sh.getRange(1,13,sh.getLastRow(),1).getValues().flat().indexOf(1) + 1;
  sh.getRange(row,1).activate();
  SpreadsheetApp.flush();
}

My active sheet:我的活动表:

COL1 COL1 COL2 COL2 COL3 COL3 COL4 COL4 COL5 COL5 COL6 COL6 COL7 COL7 COL8 COL8 COL9 COL9 COL10 COL10 COL11 COL11 COL12 COL12 COL13 COL13 COL14 COL14 COL15 COL15 COL16 COL16
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 -10 -10 14 14 15 15 16 16
2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 -9 -9 15 15 16 16 17 17
3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 -8 -8 16 16 17 17 18 18
4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 -7 -7 17 17 18 18 19 19
5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 -6 -6 18 18 19 19 20 20
6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 -5 -5 19 19 20 20 21 21
7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 -4 -4 20 20 21 21 22 22
8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 -3 -3 21 21 22 22 23 23
9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 -2 -2 22 22 23 23 24 24
10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 -1 -1 23 23 24 24 25 25
11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 0 0 24 24 25 25 26 26
12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 1 1 25 25 26 26 27 27
13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 2 2 26 26 27 27 28 28
14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 3 3 27 27 28 28 29 29
15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 4 4 28 28 29 29 30 30
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
20 20
21 21
22 22
23 23
24 24
25 25
26 26
27 27
28 28
29 29
30 30
31 31
32 32
33 33
34 34
35 35
36 36
37 37
38 38

Sheet after running the function:运行 function 后的工作表:

12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 1 1 25 25 26 26 27 27
13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 2 2 26 26 27 27 28 28
14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 3 3 27 27 28 28 29 29
15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 4 4 28 28 29 29 30 30
5 5
6 6
7 7
8 8
9 9
10 10

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google表格:根据单元格值将一行数据移动到另一张表格 - Google Sheets: Move a row of data to another sheet based on cell value Google表格脚本读取单元格“ a”的值并根据单元格“ a”的值写入单元格“ b” - Google Sheet script that reads cell “a” and writes to cell “b” based off cell “a” value 根据单元格值将行移动到其他工作表 - Move Row to Other Sheet Based on Cell Value 根据行中单元格中的值将特定行复制到新的Google工作表(JavaScript) - Copy a specific row to new google sheet based on value in a cell in the row (JavaScript) 如何使用应用程序脚本根据单元格值修改谷歌表格图表颜色 - How to modify google sheet chart color based on cell value using app script Google表格脚本:根据单元格值设置行格式-尝试优化脚本 - Google Sheets Script: Format Row Based on Cell Value - Trying to Optimize Script Google App脚本-Google Spreadsheets根据单元格值有效地移动行 - Google App Script - Google Spreadsheets Move Row based on cell value efficiently 用于复制和重命名工作表和名称的Google脚本基于单元格引用 - Google script to copy and rename a sheet and name is based on a cell reference 用于匹配和复制基于另一个相邻单元格的 Google 表格脚本 - Google sheet script to match and copy based from another adjacent cell 谷歌应用程序脚本返回单元格中的行值 - google apps script return row value in a cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM