How to Hide Images in Google Spreadsheets with Google Apps Script? - google-apps-script

I'm building a dashboard in Google Spreadsheets and want to include some images to be shown when certain rows are hidden/shown. Is this possible? I've used insertImage to insert the image but I can't find a way to delete or hide the image (hiding the rows does not affect images).
Any ideas?

There is no straightforward way of removing an image from the Apps Script API. Even if you delete a row, the image will still remain.
You should raise a request for this feature in the Issue Tracker ( http://code.google.com/p/google-apps-script-issues/issues/list ) .
EDIT:
Looks like there is already a very old issue for this https://code.google.com/p/google-apps-script-issues/issues/detail?id=64 . Along with a workaround mentioned there

Why don't you directly use the spreadsheet native function =Image(URL,section), it will be show or hide with the cells

Related

How to get image inside a form item in google apps scripts

I have multiple multiple choice questions and checkboxes with images inside them. I am trying to compile all the questions into a doc file. How do I get the images inside the questions? They are not in a separate Image Item.
https://docs.google.com/forms/d/1qdqNcaaiKxOoi4IiNc_3xcr1X3uw84qnV7mqMzcQA-0/edit?usp=sharing (This is a sample form containing an Image inside the question in case it isn't clear from the text)
Answer:
Unfortunately, at the moment there is no way to get/set images in multiple choice questions using Apps Script.
Feature Request:
There is already a feature request for setting images using FormApp, which can be found at the following link:
Add an image to a Google Form item (different from ImageItem)
You should star this issue to let Google know that this is a highly requested feature so that they can prioritise feature requests.
Alternatively, create a second Feature request specifically about getting the image and link to this one. The link to flie a feature request for Apps Script is here.
This feature has been assigned and is expected to come soon. https://issuetracker.google.com/u/1/issues/135828271 star this issue for progress updates

How to save image added in a Google Sheet cell to Google Drive?

I have a google sheet that is to be used by a third person.
The sheet contains a column that requires them to upload an image into the cell (using Google Sheets Image In Cell feature).
I want to be able to via Google Apps Script, save these images, with an appropriate name based on a value in the row, to a folder in my Google Drive.
Is this possible?
As #Tanaike said, there is currently no way to do that automatically unless you get the URL and doesnt work on generated images (like QR codes) either. Not even right click works for such.
Externally, the only solution for the moment would be to manually get a screen capture (the 'recortes' tool in Windows can help). To automate this you could do a script to move the browser, then take a capture and save it, then move the browser again, rinse and repeat , but still there is no direct solution inside Google Sheets.

How to edit choices with images in Google Script Editor?

I've got a Google Form which is attached to a spreadsheet and a script. It's got one radio button field. When a choice is made, I want to run the script to remove the choice from the list. So far so good - I've got this working well.
However, when I use images with the choices, the script removes all of the images. Is there a way of not deleting the images? Or at least a way of accessing the images associaed with a Choice to get me started?

How do I insert a Horizontal line in a google document via Google Apps Script?

I wrote a script that takes some data from a google spreadsheet and writes it in several separate tables in a google document.
Since I need to physically cut these tables from the printed document, I'd like to add horizontal lines between them.
I guess I can insert an image of a line, via
var cutline = UrlFetchApp.fetch("SOME URL");
body.appendInlineImage(resp.getBlob());
where "SOME URL" is the url for the image.
Another way I can think of would be creating a one-column table and add my tables in its cells. The horizontal lines for the table would be my cutting guides.
However, from the user interface I a horizontal line can be easily added via "Insert>Horizontal Line". I was not able to do find a way to do that from Google Apps Script.
Is this unsupported?
Can someone confirm that and/or possibly suggest method that is less cumbersome than those I thought of?
EDIT: I have also found the HorizontalRule class, which I do not understand entirely. However I don't think it's what I'm looking for.
Another alternative could be an InlineDrawing. However, from this guide, I gather that an InlineDrawing can only be manipulated, but not added programmatically.
HorizontalRule should do the magic.
This code worked for me:
DocumentApp.getActiveDocument().getBody().appendHorizontalRule();
More info:
https://developers.google.com/apps-script/reference/document/horizontal-rule#copy()
DocumentApp.getActiveDocument()..getBody().insertHorizontalRule(0)

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.