简体   繁体   English

使用带有完整日期名称的谷歌应用脚本自动滚动电子表格以显示“今天的日期”

[英]Auto Scroll through the spreadsheet to display "today's date" using google app scripts with the full date name

Hi I'm needing help in auto scrolling using app script but using the date in the full format "Wednesday 19 October 2022".嗨,我需要使用应用脚本自动滚动的帮助,但使用完整格式的日期“2022 年 10 月 19 日,星期三”。 I have used data validation and the selected date for Criteria and change the format to a custom display of [DAY(WEDNESDAY),DAY(19),MONTH(October),YEAR(2022)]我已使用数据验证和选择的标准日期并将格式更改为自定义显示 [DAY(WEDNESDAY),DAY(19),MONTH(October),YEAR(2022)]

the sheet has about 4800 rows and starts with "Tuesday 11 January 2022" and goes down all the way to "Friday 23 December 2022 " so we care currently at row 3000+/- and is becoming a pain to scroll down every time you open the sheet该工作表有大约 4800 行,从“2022 年 1 月 11 日星期二”开始,一直到“2022 年 12 月 23 日星期五”,所以我们目前关心第 3000 行+/-,每次打开时向下滚动都变得很痛苦工作表

I have though about hiding the used sheets but still needing to search and look up that data so then I have to hid and un hide the rows我虽然想隐藏用过的工作表,但仍然需要搜索和查找该数据,所以我必须隐藏和取消隐藏行

Here is an example of setting the active cell onOpen().这是设置活动单元格 onOpen() 的示例。 This example has dates in column A. If you wanted it to also work if you change the sheet you could use onSelectionChange().此示例在 A 列中有日期。如果您希望它在更改工作表时也能工作,您可以使用 onSelectionChange()。 Notice I remove the time of day from all dates to compare them.请注意,我从所有日期中删除了一天中的时间以比较它们。

function onOpen(e) {
  let spread = SpreadsheetApp.getActiveSpreadsheet();
  let sheet = spread.getActiveSheet();
  let values = sheet.getRange(1,1,sheet.getLastRow(),1).getValues();
  let today = new Date();
  today = new Date(today.getFullYear(),today.getMonth(),today.getDate());
  values.some( (row,index) => {
      let cell = row[0];
      cell = new Date(cell.getFullYear(),cell.getMonth(),cell.getDate());
      if( cell.valueOf() ==  today.valueOf() ) {
        sheet.setCurrentCell(sheet.getRange("A"+(index+1)));
        return true;
      }
      return false;
    }
  );
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM