function FindLastRowAndDate() { var ss = SpreadsheetApp.getActive().getSheetByName('Math'); ss.activate(); var LastRow = ss.getDataRange().getNumRows(); var Date = SpreadsheetApp.getActiveSheet().getRange(LastRow, 1).getValue(); SpreadsheetApp.getUi().alert("The Value for LastRow is ", LastRow, SpreadsheetApp.getUi().ButtonSet.OK); SpreadsheetApp.getUi().alert("The Value for Date is ", Date, SpreadsheetApp.getUi().ButtonSet.OK); }La primera alerta funciona bien, excepto que muestra 11.0 en lugar de 11 (como lo hace una alerta simple sin el título). ¿Alguna idea de por qué? La segunda alerta falla por excepción: los parámetros (String,(class),ButtonSet) no coinciden con la firma del método para Ui.alert. Por qué; su sintaxis me parece idéntica? Cualquier pista/solución recibida con gratitud.
Intenté usar const en lugar de var, pero eso no hizo ninguna diferencia
Descripción
Aparentemente, una alerta Ui no puede tomar un objeto Fecha. Necesita .toString() o usar Utilties.formatDate() para presentar el valor de la fecha.
Para eliminar los dígitos decimales adicionales, use .toFixed() .
Tenga en cuenta que es costumbre tener la primera letra en minúsculas en los nombres de variables y funciones. La primera letra mayúscula se usa normalmente para la clase de objeto o las variables globales.
Guion
function findLastRowAndDate() { var ss = SpreadsheetApp.getActive().getSheetByName('Math'); ss.activate(); var lastRow = ss.getDataRange().getNumRows(); var myDate = SpreadsheetApp.getActiveSheet().getRange(LastRow, 1).getValue(); SpreadsheetApp.getUi().alert("The Value for LastRow is ", lastRow.toFixed(), SpreadsheetApp.getUi().ButtonSet.OK); SpreadsheetApp.getUi().alert("The Value for Date is ", myDate.toString(), SpreadsheetApp.getUi().ButtonSet.OK); }Referencia