Skip to content

Instantly share code, notes, and snippets.

@cmilfont
Created January 16, 2012 16:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cmilfont/1621572 to your computer and use it in GitHub Desktop.
Save cmilfont/1621572 to your computer and use it in GitHub Desktop.
script do sorteio Introdução à arquitetura e design de software
function sorteio() {
var linhasTotais = SpreadsheetApp.getActiveSheet().getLastRow(), SORTEADO = "Sim!";
var LIVROS = 5;
var CURSO = "Sorteio do livro \"Introdução à arquitetura e design de software\"";
var currentSheet = SpreadsheetApp.getActiveSheet();
for (var i = 1; i <= LIVROS; i++) {
var vencedor = 1;
while (vencedor == 1 || vencedor > linhasTotais ||
currentSheet.getRange(range("D", vencedor)).getValue() == SORTEADO) vencedor = Math.ceil(Math.random()*linhasTotais);
var nome = currentSheet.getRange(range("B", vencedor)).getValue();
currentSheet.getRange(range("D", vencedor)).setValue(SORTEADO + " colocação: " + i + "º");
Browser.msgBox("Livro " + i + " vai para: " + vencedor + " => " + nome);
MailApp.sendEmail(currentSheet.getRange(range("C", vencedor)).getValue(), "Sorteio JavaCE!", "Você foi sorteado para ganhar o livro " + CURSO + ". Entraremos em contato novamente para mais detalhes.");
}
}
function range(celula, vencedor) { return celula + vencedor + ":" + celula + vencedor; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment