Problem with the Google Sheets script

  • partysquad416
    Fecha de consulta 24 de noviembre de 2023, 0:07

    Hola buena noche, tengo un formulario, el cual esta linkeado con google spreedsheet, en una parte de mi formulario se tienen que elegir 5 opciones de un universo, esas opciones al momento que el formulario las transmite a google spreedsheet se colocan en la columna R todas en la misma celda, requiero que cada opcion elegida, ocupe una celda diferente pero todas dentro de la columna R, ya que pertenecen al mismo elemento.

    Tengo el siguiente script pero al correrlo lo que hace es que separa los datos en celdas de columnas adyacentes, no sobre la columna R que es lo que yo requiero

    function separarDatosEnCeldas() {

      var hoja = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

      var datosColumna = hoja.getRange('R1:R' + hoja.getLastRow()).getValues();


      for (var i = 0; i < datosColumna.length; i++) {

        var datos = datosColumna[i][0].split(' ');

        hoja.getRange(i + 1, 18, 1, hoja.getLastColumn() - 17).clearContent();

        for (var j = 0; j < datos.length; j++) {

          hoja.getRange(i + 1, 18 + j).setValue(datos[j]);

        }

      }

    }

  • Nora Jotform Support
    Fecha de respuesta 24 de noviembre de 2023, 3:04

    Hi partysquad416,

    Thanks for reaching out to us for help. Unfortunately, our Spanish Support agents are busy helping other Jotform users at the moment. I'll try to assist you in English using Google Translate, but you can reply in whichever language you feel comfortable using. Or, if you'd prefer to receive support in Spanish, let us know and we can have them do that. But, keep in mind that you'd have to wait until they're available again.

    If you want to keep all the split data within column R, you can modify the script to achieve this. Here's a revised version of your script:

    function separarDatosEnCeldas() {
     var hoja = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
     var datosColumna = hoja.getRange('R1:R' + hoja.getLastRow()).getValues();
     for (var i = 0; i < datosColumna.length; i++) {
      var datos = datosColumna[i][0].split(' ');
      // Clear the entire column R for the current row
      hoja.getRange(i + 1, 18, 1, 1).clearContent();
      // Set each option in a separate cell within column R
      for (var j = 0; j < datos.length; j++) {
       hoja.getRange(i + 1 + j, 18).setValue(datos[j]);
      }
     }
    }

    Copy and paste this script into your Google Apps Script editor and run it. It clears the content of the cell in column R and then sets each part of the split data in the same cell but within column R.

    Give it a try and let us know how it goes.