问题
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