Creé una función personalizada en Hojas de cálculo de Google que le permite al usuario ver cuánto ha gastado en un gasto.
Aquí está la salida de ejemplo: 
La barra lateral HTML:
Aquí está la función JavaScript:
function perCentBrand(brand){ var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var values = sh.getRange(2,1,sh.getLastRow()-1,sh.getLastColumn()).getValues(); var total = 0; var sum = 0; values.forEach(function(row){ total+=row[1]; if (row[6]==brand){sum+=row[1]} }) var val = "You spent a total of " + sum + " on " + brand + " out of " + total + " ." + " Additionally, " + (sum/total)*100 + "%" + " of your income has been spent on " + brand; var ui = SpreadsheetApp.getUi(); ui.alert(val) }Y aquí está el código del formulario HTML:
<form onsubmit="runFunc()"> <input class = "u-full-width " id="brand" type = "text" placeholder="Enter brand name"> <div class="u-full-width" style="display:flex; justify-content: center"> <button type="submit" class="button-primary">Submit</button> </div> </form> He leído sobre los toLowerCase() y toUpperCase() , pero no estoy seguro de si deberían incluirse para que la entrada del usuario no distinga entre mayúsculas y minúsculas.
Gracias por adelantado.
function perCentBrand(brand){ var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var values = sh.getRange(2,1,sh.getLastRow()-1,sh.getLastColumn()).getValues(); var total = 0; var sum = 0; values.forEach(function(row){ total+=row[1]; if (row[6].toLowerCase() == brand.toLowerCase()){sum+=row[1]} }) var val = "You spent a total of " + sum + " on " + brand + " out of " + total + " ." + " Additionally, " + (sum/total)*100 + "%" + " of your income has been spent on " + brand; var ui = SpreadsheetApp.getUi(); ui.alert(val) }Supongo que quiere decir "hacer que la entrada del usuario no distinga entre mayúsculas y minúsculas" con respecto a su declaración if, por lo que controlaría el caso allí if (row[6].toLowerCase()==brand.toLowerCase()){sum+=row[1]} .