0

I use Google Sheets to produce simple quizzes for students. Instead of just having a cell display <Good!> when a kid enters a correct answer, I'd like to make a drawing pop up. A sports fan cheering, with a speech bubble, say. Google's documentation shows I can use GAS to change the size and position of a drawing, and thereby presumably make it go from effectively hidden to conspicuous. I don't foresee a problem when there's only one drawing, but if I have several, I don't see an easy way of selecting one.

I can get an array of the drawings in a sheet using getDrawings(), and use getContainerInfo() to find where the drawing is, and identify it that way, but that's pretty clunky: my code won't give any indication of what drawing is at a particular position, and if I accidentally move the drawing, my script won't select it.

Right now I'm thinking of using setOnAction() with a name that isn't actually the name of a macro, and looping through the drawings array until getOnAction() returns the name I want, but I don't know if the compiler will be happy assigning arbitrary strings via setOnAction(). I wonder if there isn't a cleaner way to do this.

0

One easyish way to show and hide images is to use Insert > Image > Image in cell and then use the Sheet.unhideRow() and Sheet.hideRow() methods to choose whether the image is visible.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.