Home > Mobile >  How can I write this array to one cell and have it like a text using GAS?
How can I write this array to one cell and have it like a text using GAS?

Time:01-22

This seems simple, but I'm sure.

The array is writte like this: ["amarelo primavera","amarelo suave","amarelo suave azul céu","azul caribe"]

But it should be written like this: amarelo primavera, amarelo suave, amarelo suave azul céu, azul caribe

I'm using setValue() to range A1 and I've tried replace(), JSON.stringify(), but none of them get me where I need.

Here's the output I get, when using the suggestion you made: enter image description here

Here's the code snippet:

function pasteColors(selectedColors) {
  const cadProdutoSheet = ss.getSheetByName('Cadastro de Produto');
  Logger.log('SelectedeColor Array: '   selectedColors);
  cadProdutoSheet.getRange("D39").setValue(JSON.stringify(selectedColors));
  SpreadsheetApp.flush();
  let a  = JSON.parse(cadProdutoSheet.getRange("D39").getValue());
  Logger.log('A: '   a);
  cadProdutoSheet.getRange(39,4).setValue(a.join(","));
}

Thank you!

CodePudding user response:

function myfunk() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  const array = ["a","b","c","d","e"];
  sh.getRange(1,1).setValue(JSON.stringify(array));
  SpreadsheetApp.flush();
  let a = JSON.parse(sh.getRange(1,1).getValue());
  Logger.log(a.join(','));
  sh.getRange(2,1).setValue(a.join(","));
}

Execution log
3:34:09 PM  Notice  Execution started
3:34:11 PM  Info    a,b,c,d,e
3:34:11 PM  Notice  Execution completed

CELL:

enter image description here

  •  Tags:  
  • Related