Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

419
Views
AppScript - Escribir en una celda específica

Estoy dando mis primeros pasos en cualquier tipo de lenguaje de codificación, soy competente con Excel/Hojas de cálculo por un tiempo y busco comenzar a automatizar algunas cosas pequeñas para facilitar un poco la vida mía y de mi equipo. Actualmente lo he escrito con éxito para copiar mi hoja de Plantilla y cambiar el nombre de la plantilla al nombre seleccionado desde un menú desplegable en una pestaña llamada "Crear hoja" (Celda J21), pero estoy luchando para cambiar el nombre de la celda B1 en la nueva hoja al nombre seleccionado también, esto es lo que tengo para copiar la plantilla. Intenté algunas cosas que encontré a través de Google y YouTube anoche para escribir también a B1 en las copias de Plantilla, pero no tuve éxito.

 function CreateSheet() { var app = SpreadsheetApp; var ss = app.getActiveSpreadsheet(); var TemplateSheet = ss.getSheetByName('Template'); var newSheet = TemplateSheet.copyTo(ss); var SheetName = ss.getRange("J21").getValue(); // Makes the new sheet the active sheet and renames it to the name in cell 'Create Sheet'J21 // ss.setActiveSheet(newSheet); ss.renameActiveSheet(SheetName); // Renames cell B1 on the new sheet to the name in 'Create Sheet'J21 // // ** this is where I am needing help **
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si desea modificar el valor de B1 de la hoja recién creada con el valor de 'Crear hoja'! J21 en la misma hoja de cálculo, puede usar esto:

 let createSheetJ21 = ss.getSheetByName('Create Sheet').getRange('J21').getValue(); ss.getSheetByName(newSheet).getRange('B1').setValue(createSheetJ21);

Pero como ya configuró newSheet como la activa, puede usar getActiveSheet alternativamente.

 ss.getActiveSheet().getRange('B1').setValue(createSheetJ21);

También puede usar la notación A1 completa en getRange (incluido el nombre de la hoja), vea el ejemplo a continuación:

 let createSheetJ21 = ss.getRange('Create Sheet!J21').getValue(); // Append `!B1` to newSheet variable ss.getRange(newSheet + '!B1').setValue(createSheetJ21);

EDITAR:

  • Al integrarlo con su script actual, debería verse como el que se muestra a continuación. Esto contiene algunas modificaciones/optimizaciones ya que hay algunos malentendidos en el actual. Vea los comentarios a continuación:
 function createSheet() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const templateSheet = ss.getSheetByName('Template'); const createSheet = ss.getSheetByName('Create Sheet'); const sheetName = createSheet.getRange('J21').getValue(); // No need to assign since copyTo doesn't return anything // By default, this creates a sheet 'Copy of <name of sheet copied>' templateSheet.copyTo(ss); // setActiveSheet takes Sheet object as input (not sheetName) // we need to create Sheet object first using its default name 'Copy of <name of sheet copied>' const createdSheet = ss.getSheetByName('Copy of Template'); ss.setActiveSheet(createdSheet); ss.renameActiveSheet(sheetName); // setValue the cells createdSheet.getRange('B1').setValue(sheetName); }

Muestra:

muestra

Producción:

producción

Referencia:

  • getRange(a1notación)
  • establecerValor(valor)
  • setActiveSheet(hoja)
  • copiar a (destino)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!