Así que tengo un script, que envía mensajes al chat grupal, si en la Columna (2) en cualquier celda, algún bot impreso "Yanson" envía solo una celda fija - .getRange(row,8) . En mi caso, esta celda contiene un enlace al documento.
El mensaje del bot se ve así: enlace al documento Nuevo nombre de la lista de documentos agregados (esta vez obtengo el nombre de la lista porque se arregló en var ws , si el script funciona en otra lista, no recibo el nombre correcto de la lista, todavía recibo el fijo) en var ws ) Si eliminamos === ws e imprimimos "Yanson" en otra lista, solo recibiré información de .getRange(row,8) y "Added New Document.
Pero necesito enviar una cadena completa (fila) con toda la celda dentro, no solo la celda 8 con enlace. Y también necesito ver en el mensaje del nombre de la lista de bots donde se imprimió "Yanson". Porque tengo más de 10+ listas en Sheet. La hoja se ve así Tablepicture
const token = "Token"; function onEdit(e) { sendTelegram(e) } function sendTelegram(e){ var row = e.range.getRow(); var col = e.range.getColumn(); var startRow = 2; // Starting row var targetColumn = 2; // If in this column, cell changes to Yanson - send to Telegram var ws = "List name"; //List name let chatId = "ChatId"; let Company = e.source.getActiveSheet().getRange(row,8).getValue(); var text = encodeURIComponent(Company + " New Document Added" + ws) var currentDate = new Date(); var url = "https://api.telegram.org/bot" + token + "/sendMessage?chat_id=" + chatId + "&text=" + text; if (col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws){ if(e.source.getActiveSheet().getRange(row,2).getValue() == "Yanson"){ //Yanson - Trigger. If Yanson printed in cell in column 2 - send to telegram sendText(chatId,Company + " New Document Added" +" "+ ws); //Doing nothig right now. // e.source.getActiveSheet().getRange(row,4).setValue(currentDate); // if(e.source.getActiveSheet().getRange(row,3).getValue() == ""){ // e.source.getActiveSheet().getRange(row,3).setValue(currentDate) // } } } }Según lo que pude deducir de su descripción, está buscando una forma de enviar todo el contenido de la fila como una cadena.
Para hacer eso, obtienes el rango de esa fila, que se ve así:
sheet.getRange(starting row, starting column, # of rows, # of cols)
Sheets usa una matriz bidimensional que se ve así:
[[row1Col1, row1Col2, row1Col3], [row2Col1, row2Col2, row2Col3], etc]
const token = "Token"; function onEdit(e) { sendTelegram(e) } function sendTelegram(e){ var row = e.range.getRow(); var col = e.range.getColumn(); var startRow = 2; // Starting row var targetColumn = 2; // If in this column, cell changes to Yanson - send to Telegram var ws = "List name"; //List name /*--- Updated this section ----*/ //Adding variables to improve readiblity var sheet = e.source.getActiveSheet(); var sheetName = e.source.getActiveSheet().getName(); let company = e.source.getActiveSheet().getRange(row,8).getValue(); var listName = ; //Is the list name the same as the sheet name? if not, reference the list names location here //Define the range of the whole row var firstCol = 1; var numOfCols = 8; var fullRowValues = sheet.getRange(row, firstCol, 1, numOfCols).getValues(); //since this is a single row, you can use .flat() to make it a 1D array //Then convert it to a string var fullRowString = fullRowValues.flat().toString(); /*---- End updates ---*/ let chatId = "ChatId"; var text = encodeURIComponent(Company + " New Document Added" + ws) var currentDate = new Date(); var url = "https://api.telegram.org/bot" + token + "/sendMessage?chat_id=" + chatId + "&text=" + text; if (col === targetColumn && row >= startRow && sheetName === ws){ if(company == "Yanson"){ //Yanson - Trigger. If Yanson printed in cell in column 2 - send to telegram // Not sure what the output is supposed to look like, // so I just added it to the end of your existing output sendText(chatId,Company + " New Document Added" +" "+ ws + " All Values: " + fullRowString); //Doing nothig right now. // e.source.getActiveSheet().getRange(row,4).setValue(currentDate); // if(e.source.getActiveSheet().getRange(row,3).getValue() == ""){ // e.source.getActiveSheet().getRange(row,3).setValue(currentDate) // } } } }function onEdit(e) { const sh = e.range.getSheet(); const row = sh.getRange(e.range.rowStart,1,1,sh.getLastColumn()).getDisplayValues()[0].join(',');//current row of active sheet const name = e.source.getName();//spreadsheet name //const name = sh.getName();//sheet name not sure which one you want sendText('chatId', `${name)\n ${row}`); }Probablemente desee limitar el activador a una hoja determinada y una fila y columna determinadas, pero eso se lo dejo a usted.