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

133
Visualizações
How to optimize this function for large dataset (100k rows & 10 cols) using Google Apps Script?

This function runs ok, but for up to 20k rows. What could I change to make it run fast?

const SOURCE_FILE_ID = 'ID';

function getData() {
  const sourceSheet = SpreadsheetApp.openById(SOURCE_FILE_ID);
  const sourceRng = sourceSheet.getSheetByName('ativcopiar').getRange(1, 1, sourceSheet.getLastRow(), 9);
  const sourceValues  = sourceRng.getValues();

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Ativ.');
  var destinationRng = sheet.getRange(1, 1, sheet.getLastRow(), 9);
  destinationRng.clearContent();

  destinationRng.setValues(sourceValues);
}

Sometimes, it exceeds the time limit.

Appreciate any light! Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I believe your goal is as follows.

  • You want to reduce the process cost of your script.

In this case, how about using Sheets API? When Sheets API is used, the process cost can be reduced a little. Ref When Sheets API is used for your script, it becomes as follows.

Modified script:

Before you use this script, please enable Sheets API at Advanced Google services.

function myFunction() {
  const SOURCE_FILE_ID = '###';
  const sheet = SpreadsheetApp.openById(SOURCE_FILE_ID).getSheetByName('ativcopiar');
  const dstSS = SpreadsheetApp.getActiveSpreadsheet();
  var dstSheet = dstSS.getSheetByName('Ativ.');
  var destinationRng = dstSheet.getRange(1, 1, dstSheet.getLastRow(), 9);
  destinationRng.clearContent();
  SpreadsheetApp.flush();
  const values = Sheets.Spreadsheets.Values.get(dstSS.getId(), "'ativcopiar'!A1:I" + sheet.getLastRow()).values;
  Sheets.Spreadsheets.Values.update({values}, dstSS.getId(), "Ativ.", {valueInputOption: "USER_ENTERED"});
}

References:

  • Benchmark: Reading and Writing Spreadsheet using Google Apps Script
  • Method: spreadsheets.values.get
  • Method: spreadsheets.values.update
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