如何在 Excel 中生成 GUID? [英] How can I generate GUIDs in Excel?

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

问题描述

我有一个excel文件,每行一个订单,我希望每个订单都有一个唯一的标识符,所以会有一个唯一ID列.每次填充一行时,我都希望 Excel 自动为我填充唯一 ID 列.我做了一些研究,并指出了 GUID 的方向.我找到了以下代码:

I have an excel file with one order on each row, and I want each order to have a unique identifier, so there will be a Unique ID column. Every time I fill a row, I want Excel to automatically populate the Unique ID column for me. I did some research and was pointed in the direction of GUIDs. I found the following code:

Function GenGuid() As String
Dim TypeLib As Object
Dim Guid As String
Set TypeLib = CreateObject("Scriptlet.TypeLib")
Guid = TypeLib.Guid
' format is {24DD18D4-C902-497F-A64B-28B2FA741661}
Guid = Replace(Guid, "{", "")
Guid = Replace(Guid, "}", "")
Guid = Replace(Guid, "-", "")
GenGuid = Guid
End Function

但我不确定如何实现它.任何帮助将不胜感激.提前致谢.

but I am not sure how I can implement it. Any help would be greatly appreciated. Thank you in advance.

推荐答案

以下 Excel 表达式的计算结果为 V4 GUID:

The following Excel expression evaluates to a V4 GUID:

=CONCATENATE(DEC2HEX(RANDBETWEEN(0,4294967295),8),"-",DEC2HEX(RANDBETWEEN(0,65535),4),"-",DEC2HEX(RANDBETWEEN(1638),20479),4),"-",DEC2HEX(RANDBETWEEN(32768,49151),4),"-",DEC2HEX(RANDBETWEEN(0,65535),4),DEC2HEX(RANDBETWEEN(32768,49151),4),DEC2HEX(RANDBETWEEN(0,7295)),8))

-或(取决于区域设置/十进制和列表分隔符)-

-or (depending on locale setting/decimal and list separators)-

=CONCATENATE(DEC2HEX(RANDBETWEEN(0;4294967295);8);"-";DEC2HEX(RANDBETWEEN(0;65535);4);"-";DEC2HEX(RANDBETWEEN(1638);;20479);4);"-";DEC2HEX(RANDBETWEEN(32768;49151);4);"-";DEC2HEX(RANDBETWEEN(0;65535);4);DEC2HEX(RANDBETWEEN(067495);4););8))

请注意,根据 RFC 4122 第 4.4 节,第三组的第一个字符始终为 4,以表示 V4(生成的伪随机数)GUID/UUID.

Note that the first character of the third group is always 4 to signify a V4 (pseudo-random number generated) GUID/UUID per RFC 4122 section 4.4.

另请注意,对于同一个 RFC,第四组的第一个字符始终介于 8 和 B 之间.

Also note that the first character of the fourth group is always between 8 and B per the same RFC.

标准免责声明:生成的 GUID/UUID 在加密方面不强.

删除不可见字符

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

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