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

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

Related

How to change the color of a bar of a chart in google sheets when a cell is populated for the bar's row

I have a google sheet that I'm working to test a small dashboard on. My goal is to show the time some units are out of manufacturing and heading to the finishing department for polish, coloring, etc. What I want to achieve is to have the color of the bar for the associated row to change color when one of the cells is populated. In my googling, I've managed to find bits and pieces, but I don't know enough JavaScript to be able to take the things I have found and use them, let alone understand them for the most part.
Here is the test sheet I've been working on: https://docs.google.com/spreadsheets/d/1b09CKYbrxe7riS6mXx6OfQk4TrQcBcghU4_YvuIt1lA/edit?usp=sharing
Basically, I want for the D Column to change the row's bar on the second tab of the spreadsheet.
I do understand it would be an onEdit(e) function and an IF statement to make it work. As well, a second function for changing the bars, but I don't know what that would be.

Script for copy over values only via button

In this sheet, I have some boxes which calculate information, (Columns K:BO)
I have drawn a button next to each box (ADD LINE)
I need a script attached to the button that will transfer only the information in the coloured cells from each box across to a "Collection Box' in Column (DC:DK)
Each box calculates differently and sometimes I may not need information from all boxes at once hence a button for each one.
The goal is to be able to organise the information so I'm able to copy and paste the information the from the Collection Box (DC:DK) as needed so I don't have to painstakingly extract the information bit by bit
For Example...
I have made a box in Columns CF:CN which only mirrors the information I require.
Problem is when I'm not using certain rows the information gets hard to read because of the cluster,
As you might see I've tried to overcome this with basic cell formatting to highlight the information that I'm using at the time
Also the cells in columns CF:CN has cell references applied so I can change the output in columns as needed.
This would be ideal for me to keep.
I'm not sure on the boundaries of the script, but is there a way that when the information is copied to the collection box so it can still utilize the cell reference to change the information without me having to re-enter?
Here is Sheet
Information is in Update Price Tab
https://docs.google.com/spreadsheets/d/1UdYCqgKEGJeh4KajxQWfTCi-JRpQgGM7435Q_VwHIH8/edit?usp=sharing
a script for copy-over values only is:
function moveValuesOnly() { var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getRange('Sheet1!A1');
source.copyTo(ss.getRange('Sheet1!B1'), {contentsOnly: true}); }
this particular one will copy values from Sheet1!A1 to Sheet1!B1 if attached to a button

Google App Script Get Selected Image Cell

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().

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.

prevent enduser to use CTRL-X / CUT on cell content

Is there a way to prevent the end-user to cut cell contents? Thus prevent using CTRL-X (and spreadsheet Menu EDIT-> Cut) but allow edit and copy cell content.
Your question is rather vague... I suppose you are trying to limit access to certain cells to 'read only' ... how is that related to GAS ?
in the spreadsheet menu you can define a named region (that can be a single cell) and choose who has access to it. As simple as that .