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

136
Views
Importar marcadores en una nueva columna en Hojas de cálculo de Google con Apps Script

Tengo esta función getMarkers() que encuentra {{marcadores}} de un documento de Google y los coloca en columnas en mi hoja de cálculo de Google. Funciona bien, pero si agrego un nuevo marcador en Doc, no se importa en una nueva columna y el contenido queda de forma incorrecta. El usuario escribe el contenido después de usar la función. Este es el esquema:

 {{marker 1}} {{marker 2}} {{marker 3}} content 1 content 2 content 3

y luego cuando agrego un nuevo marcador (entre 1 y 2 por ejemplo):

 {{marker 1}} {{new marker}} {{marker 2}} {{marker 3}} content 1 content 2 content 3

Quiero que el contenido se ajuste a su marcador.

 function getMarkers(){ var ss = SpreadsheetApp.getActive(); var sh = SpreadsheetApp.getActiveSheet(); //var ws = ss.getSheetByName('DS') || ss.insertSheet('DS', 1); var docID = "XXXXXXXXXXXXXXXXXXXXXXXX"; var docFile = DriveApp.getFileById(docID); docFile.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW); var identifier = { start: `{{`, start_include: true, end: `}}`, end_include: true }; var docMarkers = getDocItems(docID, identifier); var rw1 = [docMarkers]; var rw2 = rw1[0].map((col, i) => rw1.map(row => row[i])); var markerList = rw2[0].map((col, i) => rw2.map(row => row[i])); sh.getRange(1,1,1,rw2.length).setValues(markerList); }

.

 function getDocItems(docID, identifier){ var body = DocumentApp.openById(docID).getBody(); var docText = body.getText(); // Check if search characters are to be included. var startLen = identifier.start_include ? 0 : identifier.start.length; var endLen = identifier.end_include ? 0 : identifier.end.length; // Set up the reference loop var textStart = 0; var doc = docText; var docList = []; // Loop through text grab the identifier items. Start loop from last set of end identfiers. while(textStart > -1){ var textStart = doc.indexOf(identifier.start); if(textStart === -1){ break; } else{ var textEnd = doc.indexOf(identifier.end) + identifier.end.length; var word = doc.substring(textStart,textEnd); doc = doc.substring(textEnd); docList.push(word.substring(startLen,word.length - endLen)); }; }; //return a unique set of identifiers. return [...new Set(docList)]; }
about 4 years ago · Juan Pablo Isaza
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!