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

151
Views
¿Cómo puedo escribir el botón en las hojas de Google para 'Saltar a la fecha actual' automáticamente?

Tengo hojas enormes llenas de números: estoy buscando crear un botón en las hojas de Google que me permita saltar a la fecha de hoy (las fechas están en una columna)

sé cómo crear un hipervínculo, sin embargo, quiero hacer clic en un botón en lugar de texto; las hojas de Google solo le permiten agregar un script a un botón y no hipervínculos.

¿Alguien sabe cómo escribir un botón en las hojas de Google para saltar automáticamente a la fecha actual en la hoja?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Ir a la fecha de hoy

 function gotoCurrentDate() { const ss = SpreadsheetApp.getActive(); const sh = ss.getSheetByName('Sheet Name'); const sr = 2;//data start row const hA = sh.getRange(1, 1, 1, sh.getLastColumn()).getValues().flat();//might need to edit header row const vs = sh.getRange(sr, 1, sh.getLastRow() - sr + 1, sh.getLastColumn()).getValues(); const dt = new Date(); const dts = Utilities.formatDate(dt,Session.getScriptTimeZone(),"MMM dd, yyyy");//might want to change format const pos = { col: {}, idx: {} }; hA.forEach((h, i) => { pos.col[h] = i + 1; pos.idx[h] = i; }); vs.forEach((r,i) => { let d = new Date(r[pos.idx['Date Column Header Name']]); let ds = Utilities.formatDate(d,Session.getScriptTimeZone(),"MMM dd, yyyy");//might wat to change format if(ds == dts) { sh.getRange(i + sr, pos.col['Data Column Header Name'] ).activate() } }); }

Puede ir a Google Apps Script Reference y usar el cuadro de búsqueda para encontrar cualquier función que no entienda.

Si es una función de JavaScript puro, vaya aquí

 <input type="button" value="Go To Current Date" onClick="google.script.run.gotoCurrentDate();" />

Ponga esto en el html de una barra lateral y use la función a continuación para iniciar el salto lateral. Cuando abra un archivo html, vendrá con algo de html, colóquelo en el cuerpo y guárdelo.

Si obtiene más de un control de entrada, es posible que le guste tener esto en la cabeza.

 <style> input {margin: 1px 2px 1px 0};

gs:

 function launchSideBar() { SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutputFromFile('sidebar html file name. Do not include the extension').setTitle('Sidebar Title')) }

Así es como se ve hoy la barra lateral que uso en la hoja de cálculo en la que respondo preguntas:

ingrese la descripción de la imagen aquí

Puede usar botones directamente en la hoja de cálculo, pero personalmente creo que son un PITA.

about 4 years ago · Juan Pablo Isaza Report

0

Por si acaso, aquí está la versión lite (con un menú personalizado en lugar de un botón):

 function onOpen() { SpreadsheetApp.getUi() .createMenu('🛠️ Scripts') .addItem('Jump to current date', 'jump_to_current_date') .addToUi() } function jump_to_current_date() { var ss = SpreadsheetApp.getActive(); var sheet = ss.getSheetByName('Sheet1'); var dates = sheet.getRange('A1:A').getDisplayValues().flat(); var date = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "yyyy/MM/dd"); var row = dates.indexOf(date) + 1; if (row > 0) { sheet.getRange('A' + row).activate() } else { ss.toast('No current date was found') } }

El código busca fechas en la columna 'A' de la hoja 'Hoja1' y supone que las fechas tienen el formato '2021/11/30'. Para ejecutar el script, crea el 'Menú personalizado':

ingrese la descripción de la imagen aquí

Por supuesto, puede dibujar un 'botón' para activar la función jump_to_current_date() , si le conviene.

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!