Excel:生成特定长度的字符串引用

时间:2016-08-25 17:01:26

标签: excel excel-formula

我找到了一些可以做我想要的工具,但是尽管尝试了各种选项,但我还是无法弄清楚如何将它们放入我现有的公式中!

我正在尝试生成一个发票参考号,看起来像'ABC000012' - 第一行是ABC000001,并且每行添加时数量都会增加。我现在可以生成'ABC1'等等,但无法解决如何添加前面的0。

我目前正在使用CONCATENATE,如下所示:

=IF(ISBLANK(B2),,CONCATENATE("ABC",(ROW(1:1))))

我需要添加什么,以及在哪里,以获取我正在寻找的参考?

我也很高兴被告知如果有不同的东西可以更好地改变整个公式

由于

2 个答案:

答案 0 :(得分:2)

使用TEXT()设置前面的0:

class Meta:

enter image description here

答案 1 :(得分:1)

<Window x:Class="WpfApplication4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication4"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">

    <Grid>
        <TreeView ItemsSource="{Binding}">
            <TreeView.ItemTemplate>
                  <HierarchicalDataTemplate DataType="local:Item" ItemsSource="{Binding Items}">
                <TextBlock Text="{Binding Text}" />
               </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    </Grid>
</Window>

这是基于Scott Craner的回答。不同之处在于,它会将发票中的位数限制为6个字符。如果你想要它总是8个字符长,则将6改为8并增加“”之间的0。或者你也可以这样做:

=IF(ISBLANK(B2),"","ABC"&RIGHT("000000"&ROW(1:1),6))

在上面的公式中,要更改发票号码的位数n,您需要更改两个6的

警告:

如果列表中间有空白单元格,则会跳过每个空白单元格的数字。为避免这种情况,您需要一种与行(1:1)不同的计数方法。