How to generate an uuid in google sheet (for exemple ccb8a660-91c9-a556-58e0-4fa7-229516872004).
Either with a macro? or a formula?
You can generate a UUID using Utilities.getUuid()
. But it is required to use a custom function because there are no functions for it in Google Sheet's set of functions. In order to generate UUID, please do the following:
=uuid()
to a cell in a sheet.function uuid() {
return Utilities.getUuid();
}
When a custom function is used, the value is changed by the automatic recalculating of Spreadsheet. This example will fix the UUID.
function onEdit(e) {
if (e.range.getFormula().toUpperCase() == "=UUID(TRUE)") {
e.range.setValue(Utilities.getUuid());
}
}
function uuid() {
return Utilities.getUuid();
}
=uuid()
to a cell in a sheet.
=uuid()
is put as a custom function. So when the Spreadsheet is automatically calculated, the value is changed.=uuid(true)
to a cell in a sheet.
=uuid()
is put as a value by onEdit()
. So even when the Spreadsheet is automatically calculated, the value is NOT changed.=uuid(true)
can use when the function is manually put, because this uses the OnEdit event trigger.