Google App Script Get Selected Image Cell - google-apps-script

Hi I would like to know if its possible to scale the size of an image in a spreadsheet via Google App Script.
Basically i would like to reduce the size an image so it fits in a cell nicely then simply click on the image to see it at a viewable size.
So far i cant even get the actual cell i've clicked on.
SpreadsheetApp.getActiveSheet().getActiveRange().getValue()
Only gives me the the last selected cell and not the cell of the image i actually clicked.
Any advice would be highly appreciated.
Cheers

When you do an Insert > Image, the image just sits on top of all the cells in the sheet and I don't think we can access it.
If your images are inside of cells as a result of using the =Image() spreadsheet formula, then sure you could control the re-sizing options by changing the formula with .setFormula().

Related

Google Apps script to Change image color based on Cell Value

I have a project I'm working on improving, Right now I use Conditional formatting to apply colors to cells in google sheets to show "damage" in a table top system. as see in this image here.
https://gyazo.com/8185e4772b6e91835b7016d66694d6e4
how it works is by using the % value in the cell to tint the cell back round, very simple.
How ever I recently learned about creating an app script that can be attached to an image over the cells. like this image here.
https://gyazo.com/beccf45ef3cf20393dcdc07dd4bb33a7
I am not new to coding in google sheets and using the various functions but I am new to google apps scripts.
I know little to nothing about google app scripting so I haven't tried anything yet other than getting a bunch of syntax errors because I don't understand the language yet.
I want to write a script that for instance would when attached to the image.
if cell A3 is 20% set the tint of the image to an orange
if cell A3 is 100% set the tint of the image to an green
Or if it's even easier to simplify just use the color of the cell for a tint color.
etc
is what I'm trying to do even possible? or am I wasting my time?
I'm not very good at writing questions so if this is not clear enough I will try to edit and clarify if anyone is confused.

Google sheet: Is it possible to use app script to change a cell's dimension to certain numbers?

What I can find so far is "autoresize", but what I want is to increase the current cell to a certain dimension, for example 300x200. Is there anyway to do this?
This is part of an effort to make google sheet more image friendly. I have a sheet for products, people insert the product images "in cell", but it is by default very small. I've been trying to find a way to "click to enlarge" the image but to no avail. So I am thinking if there is a custom function that can increase the cell's dimension to certain numbers, then I can make a macro for that function so after users select the image cell, they can press the hotkey for the macro to enlarge the cell, in turn enlarge the picture, and then they can press another hotkey to return the cell to its normal size. Is this possible at all? Or is there any other better way to make google sheet more image friendly?
You can use sheet.setColumnWidth() and sheet.setRowHeight() to change the cells dimension.
If you have standard dimensions for both the normal size and enlarged size, you can set them on your code.
You can do it throught onSelectionChange(e) to automatically run the change when the user changes the selected cell(which will require you to check if that cell should be resized or not) or manually run it as a macro like you suggested.
References:
https://developers.google.com/apps-script/guides/triggers
https://developers.google.com/apps-script/reference/spreadsheet/sheet#setcolumnwidthcolumnposition,-width
https://developers.google.com/apps-script/reference/spreadsheet/sheet#setrowheightrowposition,-height

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)

Apps Script: how to programmatically resize a Google Sheets row with a wrapped cell to be smaller than the wrapped text

I've got a Google spreadsheet in which there are cells with wrapped text that become much too tall. Using Apps Script I would like to resize those rows to be shorter than the wrapped size and I don't see a way. Anybody know how it can be done?

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.