如何在 Excel 中将前导零添加到固定的字母数字长度? [复制]

Posted

技术标签:

【中文标题】如何在 Excel 中将前导零添加到固定的字母数字长度? [复制]【英文标题】:How To Add Leading Zeroes To a Fixed Alphanumeric Length In Excel? [duplicate] 【发布时间】:2021-09-29 02:29:43 【问题描述】:

我在 A 列中有以下数字,我需要将它们标准化为 B 列中的固定 8 位字母数字字符串:

    Column A     Column B
1   147731M      0147731M
2   0026146A     0026146A
3   418207L      0418207L
4   0169869M     0160869M
5   2435G        0002435G

我试过=TEXT(A2,"000000")这个公式,但它只在字母被删除时才有效。

【问题讨论】:

假设你总是有最后一个非数字,试试=CONCATENATE(TEXT(LEFT(A1, LEN(A1)-1), "00000000") ,RIGHT(A1, 1)) it works only when the letters are removed - 答案也在那里,in a comment 在答案下方。 这返回了一个#VALUE! =RIGHT("00000000" & A1, 8) 这没有给 BigBen 【参考方案1】:

你可以用这个:

=REPT("0", number_of_zeros-LEN(A1)) & A1
 ^--- repeat "0" number_of_zeros you want - length A1 and then concatenate A1

【讨论】:

以上是关于如何在 Excel 中将前导零添加到固定的字母数字长度? [复制]的主要内容,如果未能解决你的问题,请参考以下文章