Passagem de parâmetro no botão/desenho Google Sheets

0 respostas
googlejavascript
G

Como atribuir o script (com parâmetro) no desenho/botão do Google Planilhas?

O código ficou muito repetitivo, só preciso mudar uma variável e reescrever o código inteiro. Quero que a variável “col” (coluna) seja passada por parâmetro.

E quando eu atribuir a função no desenho, faça algo do tipo “formulaImage(17)”. Existe essa possibilidade?

Código abaixo:

function formulaImage() {

var ss = SpreadsheetApp.getActiveSpreadsheet();

var ui = SpreadsheetApp.getUi();

var sheet = ss.getSheets()[1];

var destinatario = ss.getRange(a1).getValue();

var formula = sheet.getRange(1, 12).getFormulaR1C1();

var numLastRow = sheet.getLastRow();
for (var i = 7; i <= numLastRow; i++) {

// LAYOUT FACE/INSTA

var col = 13;

var link = sheet.getRange(i,col).getValue();

var resultado;

var id;

var celImagem = sheet.getRange(i, col+1);
if (link != "") { 
  if (link.length == 64) {
      sheet.getRange(i, col).setValue(link);
  } else if (link.match(/id=/)) {
      resultado = link.substring(link.indexOf("id=") + 3);
      id = resultado.substring(0, 33);
      sheet.getRange(i, col).setValue("https://drive.google.com/uc?id=" + id);
      sheet.getRange(i, col+1).setValue(formula);
  } else if (link.match(/file/)) {
      resultado = link.substring(link.indexOf("file/d/") + 7);
      id = resultado.substring(0, 33);
      sheet.getRange(i, col).setValue("https://drive.google.com/uc?id=" + id);
      sheet.getRange(i, col+1).setValue(formula);
  }
} else {
  
}
if (link != "") {
  sheet.getRange(i, col+1).setValue(formula);
} else {

}

}

for (var i = 7; i <= numLastRow; i++) {

// LAYOUT STORIES

var col = 15;

var link = sheet.getRange(i,col).getValue();

var resultado;

var id;

var celImagem = sheet.getRange(i, col+1);
if (link != "") { 
  if (link.length == 64) {
      sheet.getRange(i, col).setValue(link);
  } else if (link.match(/id=/)) {
      resultado = link.substring(link.indexOf("id=") + 3);
      id = resultado.substring(0, 33);
      sheet.getRange(i, col).setValue("https://drive.google.com/uc?id=" + id);
      sheet.getRange(i, col+1).setValue(formula);
  } else if (link.match(/file/)) {
      resultado = link.substring(link.indexOf("file/d/") + 7);
      id = resultado.substring(0, 33);
      sheet.getRange(i, col).setValue("https://drive.google.com/uc?id=" + id);
      sheet.getRange(i, col+1).setValue(formula);
  }
} else {
  
}
if (link != "") {
  sheet.getRange(i, col+1).setValue(formula);
} else {

}

}

for (var i = 7; i <= numLastRow; i++) {
// LAYOUT WPP

var col = 17;
var link = sheet.getRange(i,col).getValue();
var resultado;
var id;
var celImagem = sheet.getRange(i, col+1);

if (link != "") { 
  if (link.length == 64) {
    sheet.getRange(i, col).setValue(link);
  } else if (link.match(/id=/)) {
    resultado = link.substring(link.indexOf("id=") + 3);
    id = resultado.substring(0, 33);
    sheet.getRange(i, col).setValue("https://drive.google.com/uc?id=" + id);
    sheet.getRange(i, col+1).setValue(formula);
  } else if (link.match(/file/)) {
    resultado = link.substring(link.indexOf("file/d/") + 7);
    id = resultado.substring(0, 33);
    sheet.getRange(i, col).setValue("https://drive.google.com/uc?id=" + id);
    sheet.getRange(i, col+1).setValue(formula);
  }
} else {
  
}
if (link != "") {
  sheet.getRange(i, col+1).setValue(formula);
} else {
  
}

}

}

Criado 30 de novembro de 2018
Respostas 0
Participantes 1