Google Apps Spreadsheet open specific sheet based on week number - google-apps-script

I know the solution "move sheet to the most left" to make it default when opening spreadsheet.
Thing is that I got one spreadsheet per week, and it's quite messy to move around like that, plus it will be much more user friendly.
Something similar to this
Google Apps Spreadsheet open specific sheet based on current date (Month)
Weeknum is a rather new function in google docs, so I haven't found anything else googling around.

Related

Importfeed function not loading RSS feed entries sometimes

I have been using this sheet and many similar sheets for a long time but I have been facing this issue in many of the sheets. After a few days, the "importfeed" function stops loading the values on to the sheet. When I make a copy of the sheet (new spreadsheet), it instantly shows the values on the new sheet. It is a solution I do not want to use as I am using the script at different places and in that case I will have to change the script id everywhere. Please find the screenshot of the issue attached to this question below:
FYI, I am using a code to refresh the "importfeed" function every minute to get latest data. Any help would be great. Thanks

Check which sheets are currently being viewed in your spreadsheet

to explain the issue briefly, there are certain sheets in the spreadsheet that are supposed to be hidden constantly.Though they have to be opened sometimes to change some data on them. The issue is that there are multiple collaborators on the spreadsheet getting annoyed by people leaving these sheets open and not hiding them again after they're done.
I have a lot of stuff on the sheet automatized through a minutely cycle anyhow so my first approach was to just hide them every cycle if they've been left open. The problem there is that the hideSheet() figuratively slaps the sheet out of your hand even if you're actively viewing it which shouldn't be happening.
I know that there are functions like getActiveSheet() and after some testing I've seen that this function, if you run it for yourself, returns the sheet you're currently viewing (like I myself am viewing).
My idea to overcome the problem that the hideSheet() function also closes the sheet you're currently viewing was to check whether the sheet is currently active for someone on the spreadsheet.The "myself" case obviously works here as I can just check whether I am viewing the sheet as a case for hiding it or not.
Long story short, does anyone have an idea how I can get a list of sheets that are currently being viewed or like being open on other peoples' ends?
Or if that's not possible to answer, does anyone know how I can ensure that the sheets are being rehidden on a regular basis without having the problem that I might just throw someone out of the sheet while he still has it open?
Try the change installable trigger.
An installable change trigger runs when a user modifies the structure of a spreadsheet itself—for example, by adding a new sheet or removing a column.
It might be triggered by showing/hiding a sheet. If so, your script could log when a sheet was shown then do something with that like polling the active sheet when the edits / change the spreadsheet and if the active sheet is not the same, then hide the sheet that was shown.
Reference
https://developers.google.com/apps-script/guides/triggers/installable

How to protect the cell/range at the same time as appendrow

Im working on a website that stores data in a google spreadsheet and was wondering how I could use the appendrow() function and then protect that cell so no one can access it.
I'm new to google apps script and have been searching the internet for the last hour or so and can't find anything.
sheet.appendRow([text]);
But after that I would like it to get the value of that cell that was just written on so I could write:
var protection = the-row-just-written-on.protect()
I I am hoping for the result to be that no one can delete the text once it has been written on.

Script Execution when Switching Sheets withing the Same Spreadsheet

I'm running an online booking sheet for my local squash club (dragging them into this century!) and need to find an easy way to automate navigation to the current date when #1 opening the spreadsheet, an #2 switching sheets while the spreadsheet is open. Without the feature, people will have to endlessly scroll through the season to find today's date.
I've run a formula in column A that will place an * on the row that =TODAY() and would appreciate a bit of advice from people with script writing skills as to whether it would be possible to go to that cell on start up, and when we switch between sheets (we run 2 courts, on separate sheets).
As always, help is very much appreciated, and hopefully there is something that can be introduced that can help.
[edit] I suppose the simplest way, looking back at it now, would be the following I just need to learn how to code it:
OnOpen - Set the active sheet as "COURT 1"
Set the active range for the function as A:A
Go to the last modified cell in that range (as it's always going to the be the cell that I want).
The script should then repeat the process for "COURT 2" and then return to "COURT 1".
Copy of the spreadsheet can be found here:
https://docs.google.com/spreadsheets/d/1NBom_qB9AM_LG2lgrGjNRDbxbSGysVj8H6AXqdgKWD8/edit?usp=sharing
Thanks :)
Mark
Some key concepts that might help. I highly advise that you learn how to script so you don't go asking for code each time you want to modify something.
To run a script upon opening the sheet, you can make use of onOpen() trigger. On the same note, you need to be aware of this trigger's Restrictions.
To operate on another sheet within the same SpreadSheet, use setActiveSheet(sheet). When the sheet becomes active, you can now do operations on it. Check the SpreadsheetApp for more docs info.

Automatically Restore Previous Version of a Google Document

I work in a school, and have teachers fill out a point chart every week in google sheets. At the end of the week, I save the information and restore the sheet to it's blank state as it was at the beginning of the week.
I'm looking for an add-on that will automatically restore a previous version of my sheet on a weekly basis at a certain time. Have you ever come across an add-on that does something similar?
For this you can write an Apps script function with the content below:
// This example assumes there is a sheet named "first"
var ss = SpreadsheetApp.getActiveSpreadsheet();
var first = ss.getSheetByName("first");
first.clearContents();
And add a time driven trigger to that function to run once a week.
Hope that helps!