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

Time:12-28

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?

CodePudding user response:

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