Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

381
Visualizações
How to setFormulas() to a range using Google Apps Script?

What do I need to change so that this script sets the formulas (from row 2) to the range defined? The code below doesn't give me any error, but it doesn't set the formulas at all.

  var lc = sheet.getLastColumn();
  var range = sheet.getRange(2, 1, 1, lc);
  var formulas = range.getFormulas();
  
  range.copyFormatToRange(sheet, 1, lc, 3, 3+response); //This pastes the format to the range, whose number of rows is defined depending on the # that the user inputs.

  var pasteTo = sheet.getRange(3, 1, response, lc);//Defines the range for setting formulas
  for (var a = 3; a < response; a++){
    pasteTo = sheet.getRange("A" + a,sheet.getLastColumn());
    pasteTo.setFormulas(formulas);
  }
  }
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Doing everything in Arrays is much faster

function kdkdkd() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet0');
  const osh = ss.getSheetByName('Sheet1');
  const fA = sh.getRange(2, 1, sh.getLastRow() - 1, sh.getLastColumn()).getFormulas();
  osh.getRange(row,col,fA.length,fA[0].length).setFormulas(fA);  
}

pick whatever you want for row and col

about 4 years ago · Juan Pablo Isaza Relatório

0

Thank you, @TheMaster, for the orientation: The signature is .getRange('string')(a1notation) or .getRange(number,number)(row, column ), but there's no .getRange('string',number)

Here's how I solved it:

  var lc = sheet.getLastColumn();
  var range = sheet.getRange(2, 1, 1, lc);
  var formulas = range.getFormulas();
  
  range.copyFormatToRange(sheet, 1, lc, 3, 3+response);

  var pasteTo = sheet.getRange(3, 1, response, lc);
  for (var a = 1; a <= response; a++){
    pasteTo = sheet.getRange(a+2,1,1,lc);
    pasteTo.setFormulas(formulas);
    }
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda