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

291
Visualizações
Splitting sheet text using an array to mantain unique ID

I'm using this: How to transpose and split in Google Apps Script?

Which works great in the first part (I use it to copy data an split it) but then I would need to redo it since I have 2 different separators, first time ";" second time ",".

The issue and I'm guessing it's more JS related than anything else, is that if I use the same for it splits the 2nd column vertically. I'll post examples.

Column A has the ID, Column B has the comma separated text

If I use it again to reformat it gives this:

enter image description here

I would like it to be split into Column B and C.

I figured it was because the for loop only pushes 2 rows, but I can't solve adding a third.

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

0

Issue:

If I understood it correctly, you have something like this:

enter image description here

And you would like to end up with something like this:

enter image description here


Solution:

The following code will do just that, splitting (and putting into several lines) the values in the first image by ;, and then separating the quantity from the product name (accomplished by splitting the ,).

function myFunction() {
  
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheetByName("Sheet1");

  var range = sheet.getRange(2,1,sheet.getLastRow()-1,2);
  var values = range.getValues();

  var valuesToInput = [];

  for(var i = 0; i<values.length; i++){
    var productList = values[i][1].split(";");
    
    for(var j = 0; j < productList.length; j++){
      var productVariables = productList[j].split(",");
      var productQuantity = productVariables[0];
      var productName = productVariables[1];

      valuesToInput.push([values[i][0], productQuantity, productName]);
    }
  }

  var rangeToInput = sheet.getRange(2,1,valuesToInput.length, 3);
  rangeToInput.setValues(valuesToInput);
}

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