Is there a way to get Google Sheets to default to a different tab each day?

半世苍凉 提交于 2021-02-10 17:26:46

问题


I have an MVC application that links to a Google Sheet doc via siteloader. It's loading great but defaulting to load the first tab in the sheets - working as designed obviously.

Here's what I need to do:

The tabs in this sheet are separated by date. So, for example, today's 8/22/20. The tab displays "SAT 082220." Tomorrow's tab will be "SUN 082320" and so on.

I need siteloader to default to today's tab when the project loads. So basically it just needs to load the next tab in the list each day.

Does anyone have any thoughts on how to accomplish this?

I know Google Sheets assigns its own unique URL to each tab in the sheet via the edit#gid= in the URL.

Is there a pattern to the tab URL so I could have siteloader constantly just load the next tab in the list each day? i.e. edit#gid=1068387962 for today's tab and edit#gid=somethingsomething for tomorrow's?

I'm thinking that may be the easiest way. From what I can see, though, it all looks random.

Alternatively, is there a way to get razor to read the tabs and match the tab name with DateTime.now?


回答1:


onOpen trigger on apps script can do this:

/**
 * @param {GoogleAppsScript.Events.SheetsOnOpen} e
 */
const onOpen = e =>
  e.source
    .getSheetByName(
      Utilities.formatDate(
        new Date(),
        e.source.getSpreadsheetTimeZone(),
        'EEE MMddyy'
      ).toUpperCase()
    )
    .activate();


来源:https://stackoverflow.com/questions/63542077/is-there-a-way-to-get-google-sheets-to-default-to-a-different-tab-each-day

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!