Google表格-打开表格时如何跳至今天的日期(通过共享链接) [英] Google Sheets - How to jump to today's date when opening a table (via share link)

查看:92
本文介绍了Google表格-打开表格时如何跳至今天的日期(通过共享链接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您的精彩帖子!

我正在寻找一个代码,该代码将导致在Google表格中打开表格(通过共享链接)后自动跳至当前日期.如果我登录,则您的代码(请参见下文)效果很好.创建共享链接(具有或不具有编辑权限)时,该代码不起作用.我尝试了使用其他浏览器(Chrome,Edge,Firefox)的链接...可能是什么问题?

I am looking for a code that will cause jumping automatically to the current date after opening a table in Google Sheets (via a share link). Your code (see below) works great if I am signed in. When I create a share link (with or without edit rights), the code does not work. I tried the link with different browsers (Chrome, Edge, Firefox) ... What could be the problem?

    function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getActiveSheet();
  var data = sh.getDataRange().getValues();
  var today = new Date().setHours(0,0,0,0);
  for(var n=0;n<data[0].length;n++){
    var date = new Date(data[0][n]).setHours(0,0,0,0);
    if(date==today){break};
  }
  n++;
  sh.getRange(1,n).activate();
}

亲切的问候

这里是您的代码的链接:

Here the link to your code: How to set background color for a row based on current date in Google Docs Spreadsheet?

推荐答案

onOpen(e)函数是

The onOpen(e) function is a simple trigger that runs only if the user at the keyboard is signed in to their Google account and has edit access to the spreadsheet.

简单触发器 onOpen(e) onEdit(e) onSelectionChange(e)在以只读模式打开文件时运行.其他类型的脚本也是如此.换句话说,如果您以可以查看"的方式共享文件,或可以发表评论",则不会提供任何脚本或加载项.

The simple triggers onOpen(e), onEdit(e) and onSelectionChange(e) will not run when a file is opened in read-only mode. The same is true with other kinds of scripts as well. In other words, if you share the file as "can view" or "can comment", no scripts or add-ons will be available.

要使其正常工作,您将必须以可以编辑"的方式共享电子表格文件.请注意,您仍然可以通过 Data>受保护的工作表和范围.

To make it work, you will have to share the spreadsheet file as "can edit". Note that you you can still protect the spreadsheet through Data > Protected sheets and ranges.

请参见 jumpToToday_ 脚本以获取支持多张工作表的替代方法在同一电子表格文件中.

See the jumpToToday_ script for an alternative that supports multiple sheets in the same spreadsheet file.

这篇关于Google表格-打开表格时如何跳至今天的日期(通过共享链接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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