1

With google apps script, we can write spreadsheet functions that we can call from a cell like:

function f() {
  return [['A', 'B'],['C', 'D']];
}

Then if we fill a cell with =f(), A 2x2 group of cells are filled with the values 'A', 'B', then 'C', 'D', starting from the cell we entered the formula.

Is there any way we can also set the formatting of the cell from this return value? Maybe instead of returning a plain string for each cell, we can return an object which may contain a 'value' key and a 'format' key?

krafczyk
  • 49
  • 1
  • 2
    No `````````````````​````````````````` – TheMaster Aug 31 '20 at 14:31
  • Custom functions are intended to imitate plain functions like `=SUM()`. Just like plain functions can't do such format stuff, custom functions also can't. There are [workarounds](https://stackoverflow.com/a/52787692/), but not recommended from a security perspective. – TheMaster Aug 31 '20 at 14:38
  • Okay, thanks for the explanation. I'll try to do this formatting manually then. – krafczyk Aug 31 '20 at 15:02
  • @krafczyk you don't have to do it manually. You just can't do it using custom functions. You can create a regular function and run it either from the script editor or a custom menu . – Marios Aug 31 '20 at 15:11
  • That's likely to not be worth the time. Code I'd have to write to do that would have to determine what sections of my spreadsheet are headers and which are values. This is somewhat difficult, and given how hard it is to debug google script functions, likely wouldn't be worth my time. I use this spreadsheet about once a month, and adding the formatting by hand takes me < 1 min. – krafczyk Sep 01 '20 at 14:25

0 Answers0