Double clicking Google Sheet Drawing with attached script opens Drawing editor - how to avoid? - google-apps-script

I'm using a Drawing as a way to call a script. My use case expects this button to be pressed in rapid succession sometimes (two or three times at once).
I simply want the button to call the script multiple times (it does) without opening the edit drawing dialog.
Are there permissions I can set to prevent the user from opening this dialog?
Or is there a way to lock the drawing?
Or is there a different way to create a button that can be used in this way? (I looked at onSelectionChange(e) but this doesn't solve my multiple click need.)
Thank you.

A simple solution is to not use a drawing at all. Here's how:
Make a nice snip of the UP arrow, and copy it to the clipboard
Select the cell where the arrow is now and delete the Drawing.
In the same cell paste the snip from the clipboard
Right click on the pasted Arrow image and assign the script to it.
Notice that you can click many times and it will work as you expect.
Repeat for the DOWN arrow.

Related

Is there any way to change a Google Slides presentation without reloading it?

I'm basically trying to build a game board. For simplicity's sake, imagine a Jeopardy! board. I'd like to be able to click on a square (imagine it says $200) and go to the question set for that square. Then, when I return to the main board, I'd like that square that I clicked on ($200) to be blank, so I know I've already clicked it.
I want to be able to do this in a full screen presentation, without having to reload the slideshow at all.
I'm thinking, hoping, I could do a script that would just straight-up replace the image of a screen with text on it, to an image of a blank screen, but I'd also be okay with building the slide with two layers of images - one with text above one without - and deleting the top layer when it's clicked.
Click on and it becomes this:
Replacing the image via script can be easily done by using the following script:
function myFunction() {
var image = SlidesApp.getActivePresentation().getSlides()[0].getImages()[0];
// Get the Drive image file with the given ID.
var driveImage = DriveApp.getFileById('File ID of the new image');
image.replace(driveImage);
}
But unfortunately, assigning an image to act as a button to run script is only available on Google Spreadsheet. And by further checking it seems somebody already submitted a Feature Request for such a feature to be implemented on Google Slides as well.
References:
https://developers.google.com/apps-script/reference/slides/image#replace(BlobSource)

Is it possible to create macro buttons to navigate in Google Sheets?

I am creating a database in Google Sheets per the link below:
Database
I would like to add buttons like you can in excel where you can record a macro to navigate or open another sheet or perform a particular function. For example in my database, I could create a home page with buttons to open certain sheets. I could then hide all of the sheets and only have a home page.
Or, perhaps hide the query data in cell C2 in the 'Other Attendances' sheet and create a button to open up the query.
Is any of this possible in Google Sheets?
Let's create a button to go to the left hand most page. Please select one of the right hand pages or push the + sign in the lower left to create one.
Here's the script:
function gotoMostLeftPage() {
var ss=SpreadsheetApp.getActive();
ss.setActiveSheet(ss.getSheets()[0]);
}
Now we need a button:
We can use insert/Drawing to draw an image of our drawing.
In this case I'm using a basic shape. You can add text if you like.
Now just save and close.
Drag the button to where you want it and click on the three buttons in the upper right.
Select Assign script.
Copy the script name.
Paste it into the dialog and click ok.
Try clicking on the button and it should take you to the left most page unless you are already there.

Selecting/highlighting next adjacent cell in row after function has been executed in google script

I am not really experienced with coding so I apologize in advance if this is a stupid question with an obvious answer...
I use a google sheet to keep track of things at work, and my employees use it multiple times a day. They will either type one of three phrases into a certain cell on a row, so I have created buttons using the drawing feature that they can simply click, which will insert the appropriate text into the highlighted cell.
Once this text is inserted into the cell, I would like to add something to the end of the function that automatically selects the next adjacent cell in the row (to the right) so they can continue typing in. Currently, once they click the button to insert text into one cell (e.g., B23) they have to use the mouse to manually select C23 before typing into that cell. For some reason you cannot use the right arrow key or tab key on the keyboard to move over, so I am wondering if there is a way to add the selecting process into the script (or even a workaround for allowing the tab or right arrow keys to work).
I realize this may seem like a tedious question and folks may think it is awfully lazy of me to ask for a more efficient way to move over to a cell than using the mouse, but my employees use the sheet hundreds of times a day, so I'd really like to maximize the efficiency for them to make it as easy and convenient as possible. Inputting data can be tedious enough, so I am trying to simplify things and make it as least painful as possible :)
Thanks so much!
There are several ways to select the cell at the right. One way is to use offset(rowOffset,columnOffset):
range.offset(0,1)
You are correct. When using a button the focus stays in the button when it is clicked. After some trial and error, I think I found a way that will work fot you. I created a html sidebar that is opened from a custom menu. Once opened, you can leave it opened, HTML allows control over the focus using 'google.script.host.editor.focus()'. Then you can type in the cell. Attached is my sample spreadsheet you can copy and try. Let me know if you need any help changing the button names or text. Sorry my first try didn't work correctly. https://docs.google.com/spreadsheets/d/1KlNSJnZDNIb2chUK3SlKJg79VNIrsAbIbUvHyLwTLWk/edit?usp=sharing

How to call a script in Google Spreadsheet above a frozen row?

Above a frozen row I want to put an image that is linked to a script; e.g. click the image and a script runs.
I can insert an image and add a script to it, problem: can only be
done under frozen row.
I can insert an image using =image("imageurl";2), I can even put a
hyperlink to this =hyperlink("url"; image("imageurl";2)) and this
works nicely but I can't call a script.
Any ideas on how to solve this?
How do you add UI inside cells in a google spreadsheet using app script? ... shows how to insert a drawing and link it to a script. Unfortunately, as you've found, floating images are not allowed in frozen rows or columns, so that technique breaks down if you must freeze rows. A quick search on the interwebs will show that this has been a long-term complaint about Google Sheets. (For instance.)
There are options, none of them ideal:
Use a custom menu function instead. That means users need to hunt a bit to find the menu option to kick your script, but it does stay in view no matter where they are.
Use the hyperlink & image work-around you've described, but use a published script url as the target. That will allow you to run a google apps script, indirectly.
Use a sidebar. OK, this isn't actually supported in Sheets yet - visit Issue 3162 and star it for updates.

Linking one cell to another in a spreadsheet

I have a dynamically generated spreadsheet. I would like to be able to allow the viewer to go to a different sheet/cell when a cell is clicked on. I'm having trouble figuring out a good way to do this.
Going to the new cell is fairly easy: Spreadhseet.setActiveSheet()/Spreadsheet.setActiveRange() work fine. My thought was to encode the link destination in the contents of the source cell, and then write a script to "follow" the link.
I tried using images or drawings. But there were two problems with this: while images can be inserted programmatically, I did not see a way to programmatically associate a script with them. And the called script does not have an associated event tied to it, so there is no way to see what cell the user clicked (clicking an image does not set the active cell).
I thought about using onEdit(). This almost works, but onEdit is only triggered on changes (not selection) so the user actually has to modify the cell in order to "link". When testing I tended to zap the contents of the cell by accident with onEdit.
I tried making a menu item, and in the menu's script get the active cell's contents to determine where to go to. This worked but was a bit more difficult for the user than I was hoping for.
I was hoping someone would have a creative solution to this problem.
Thanks!
From what you are describing the drawing or image insertion should work since it has exactly the same functionality as the menu item. You can assign a script to it just like in a menu.