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

425
Visualizações
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 Respostas
Responde à pergunta

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 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