Created
January 16, 2012 16:12
-
-
Save cmilfont/1621572 to your computer and use it in GitHub Desktop.
script do sorteio Introdução à arquitetura e design de software
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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