Dancul
Dancul

Reputation: 21

Array values to cells

I have google script for changing text in rows. Problem after text modification is that I do not know how to save array values to cells in second sheet.

// Array to cells

function textReplaceLoop2() {

 var sheet = SpreadsheetApp.getActive();
 var ss1 = sheet.getSheetByName('Sheet1');
 var ss2 = sheet.getSheetByName('Sheet2');

 
 // reading valies and couting number of rows 
 var arraytexttomod = ss1.getRange(2,1,ss1.getLastRow(),1).getValues();
 var numofrowsfix = arraytexttomod.length -1 ;
 Logger.log(numofrowsfix);

  var arraymod = new Array;

// loop text modification
  for (var i = 0 ; i < numofrowsfix ; i++ ) {
  var textmodread = arraytexttomod[i];
  textmodmod = textmodread.toString().replaceAll(".", "");

  //Logger.log(textmodmod);
  arraymod[i] = textmodmod;
   
}

Logger.log(arraymod);  
ss2.getRange(2,1).setValues([arraymod]);  // NOT WORKING,  ONLY WORKING FOR COLUMNS WITH RANGE (2,1,1,132) BUT NOT FOR ROWS 
}

log: enter image description here

Upvotes: 0

Views: 1002

Answers (1)

Dmitry Kostyuk
Dmitry Kostyuk

Reputation: 1459

Assuming that you want it as a column, try this:

const col = arraymod.map(value => [value]);
ss2.getRange(2, 1, col.length, col[0].length).setValues(col);

Upvotes: 1

Related Questions