如何在Google工作表中生成uuid? [英] How to generate an uuid in google sheet?

查看:118
本文介绍了如何在Google工作表中生成uuid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Google工作表中生成uuid(例如ccb8a660-91c9-a556-58e0-4fa7-229516872004).

How to generate an uuid in google sheet (for exemple ccb8a660-91c9-a556-58e0-4fa7-229516872004).

要么带有宏?或公式?

推荐答案

您可以使用Utilities.getUuid()生成UUID.但是需要使用自定义函数来实现所需的功能,因为Spreadsheet的函数中没有针对该函数的函数.为了生成UUID,请执行以下流程.

You can generate UUID using Utilities.getUuid(). But it is required to use a custom function for achieving what you want, because there are no functions for it in Spreadsheet's functions. In order to generate UUID, please do the following flow.

  1. 打开脚本编辑器以创建Google Apps脚本.
  2. 复制并粘贴以下脚本并保存.
  3. =uuid()放入工作表中的单元格.
  1. Open the script editor for creating Google Apps Script.
  2. Copy and paste the following script and save it.
  3. Put =uuid() to a cell in a sheet.

通过此操作,您可以获得UUID.

By this, you can get UUID.

function uuid() {
  return Utilities.getUuid();
}

参考:

  • getUuid()
  • Reference :

    • getUuid()
    • 如果我误解了你的问题,对不起.

      If I misunderstand your question, I'm sorry.

      使用自定义函数时,将通过自动重新计算电子表格来更改值.如果要固定该值,该示例脚本如何?请认为这只是几种解决方法之一.

      When a custom function is used, the value is changed by the automatically recalculating of Spreadsheet. If you want to fix the value, how about this sample script? Please think of this as just one of several workarounds.

      function onEdit(e) {
        if (e.range.getFormula().toUpperCase()  == "=UUID(TRUE)") {
          e.range.setValue(Utilities.getUuid());
        }
      }
      
      function uuid() {
        return Utilities.getUuid();
      }
      

      • 使用此脚本时,请执行以下流程.

        • When you use this script, please do the following flow.

          1. 将脚本复制并粘贴到电子表格的绑定脚本并保存.
          2. =uuid()放入工作表中的单元格.
            • 在这种情况下,=uuid()被放置为自定义函数.因此,当自动计算电子表格时,该值就会更改.
          1. Copy and paste the script to the bound-script of Spreadsheet and save it.
          2. Put =uuid() to a cell in a sheet.
            • In this case, =uuid() is put as a custom function. So when the Spreadsheet is automatically calculated, the value is changed.
          • 在这种情况下,=uuid()onEdit()放置为值.因此,即使自动计算了电子表格,该值也不会更改.
          • In this case, =uuid() is put as a value by onEdit(). So even when the Spreadsheet is automatically calculated, the value is NOT changed.

          • 在这种情况下,=uuid(true)可以在手动放置函数时使用,因为它使用了OnEdit事件触发器.
          • 这是一个简单的示例脚本.因此,请根据您的情况进行修改.
          • In this case, =uuid(true) can use when the function is manually put, because this uses the OnEdit event trigger.
          • This is a simple sample script. So please modify this for your situation.

          这篇关于如何在Google工作表中生成uuid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆