Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
Actualice múltiples pestañas usando el script de aplicaciones

Tengo una hoja llamada "Main_Sheet". Tengo varias pestañas (Este, Central) para cada valor de columna en Col_B. Cada semana se agregan nuevos registros a la hoja principal. Quiero una función de script de aplicaciones de Google para insertar nuevas filas desde la pestaña Main_Sheet a las pestañas correspondientes.

Hoja de entrada:

Hoja_principal

Salida_Hojas Centro Este

Pasos a seguir: Las filas delineadas son nuevas (porque aún no existen en las Hojas Este y Central). Tome estas filas y pegue sus valores en las pestañas correspondientes (Este y Centro)

ingrese la descripción de la imagen aquí

La hoja de salida debe tener el siguiente aspecto:

Después de ejecutar el script, las filas resaltadas deben agregarse a la pestaña "Este":

ingrese la descripción de la imagen aquí

Del mismo modo, Central se vería así:

ingrese la descripción de la imagen aquí

Dado que la pestaña "Oeste" no existe, me gustaría que la secuencia de comandos cree una nueva pestaña e inserte registros

Soy nuevo en las hojas de Google y el script de aplicaciones, por favor ayuda.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

En su situación, ¿qué tal el siguiente script de muestra?

Guión de muestra:

 function myFunction() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheets = ss.getSheets().reduce((o, s) => (o[s.getSheetName()] = s, o), {}); const main = ss.getSheetByName("Main_Sheet"); const [header, ...values] = main.getDataRange().getValues(); const col = main.getLastColumn(); const obj = values.reduce((o, r) => (o[r[1]] = o[r[1]] ? [...o[r[1]], r] : [r], o), {}); Object.entries(obj).forEach(([s, v]) => { if (v.length == 0) return; if (sheets[s]) { const sheet = sheets[s]; const temp = sheet.getDataRange().getValues().reduce((o, r) => (o[r.join("")] = true, o), {}); const values = v.filter(r => !temp[r.join("")]); if (values.length > 0) { const lastRow = sheet.getLastRow(); sheet.getRange(lastRow + 1, 1, values.length, values[0].length).setValues(values); main.getRange("A2:2").copyFormatToRange(sheet, 1, col, lastRow + 1, lastRow + values.length); } } else { const values = [header, ...v]; const sheet = ss.insertSheet(s); sheet.getRange(1, 1, values.length, values[0].length).setValues(values); main.getRange(1, 1, 1, col).copyFormatToRange(sheet, 1, col, 1, 1); main.getRange("A2:2").copyFormatToRange(sheet, 1, col, 2, values.length); } }); }
  • En este script de ejemplo, los valores se recuperan de "Main_Sheet". Y recupera cada valor para cada hoja, y cada valor se coloca en cada hoja.

  • Acerca de su solicitud adicional de Can you please include headers as well. Right now the headers are missing. Once you add headers I will test again , lo reflejé.

  • Acerca de su solicitud adicional de the header row is in bold values in the "Main_Sheet" tab. With your code, the headers are just being copied as plain text. I want the format of header to be same in all tabs , lo reflejé.

  • Acerca de su solicitud adicional de I am saying that I want to keep the format from the main_sheet tab consistent with other tabs. So if Main_sheet has blue and bold headers, the code should copy the header value and format into the new tab. , lo reflejé.

  • Acerca de su solicitud adicional de The goal is the paste the values from Main_Sheet to the correct tabs. The format(of header and all other rows) in main_sheet should be same as Central, East, West Tab. Right now your code is pasting plain values(it is not pasting the correct format from the Source sheet--> Main_Sheet)... Right now only header row has the correct format in the output tabs. Please preserve the format of the non header rows as well , lo reflejé.

Nota:

  • Este script de muestra es para su hoja de cálculo de muestra. Por lo tanto, cuando se cambia su hoja de cálculo, es posible que no se pueda usar este script. Tenga cuidado con esto.

Referencias:

  • reducir()
  • filtrar()
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda