简体   繁体   English

将文本反转为Excel / Calc中的列

[英]Reversing Text to Columns in Excel/Calc

Most spreadsheet software I've used has a text-to-columns function that splits a single column into multiple columns using several criteria (delimiter, # of character, etc). 我使用的大多数电子表格软件都具有text-to-columns功能,该功能使用多个条件(定界符,字符数等)将一列拆分为多列。 I want to do this in reverse . 我想反过来做。

I know I can use a formula to create a third column with the values of the two cells concatenated together with a delimiter between them but this seems clunky. 我知道我可以使用公式创建第三列,将两个单元格的值连接在一起,并在它们之间使用分隔符,但这似乎很笨拙。

Why is this not a built in function? 为什么这不是内置函数? Or is it there somewhere that I can't see? 还是在我看不见的地方?

There are built-in functions that will allow you to combine multiple cells into one with a delimiter between each. 内置的功能可让您将多个单元格合并为一个,并在每个单元格之间使用定界符。

Let's say you want to join cells A1 to A5 with a , in between each value. 比方说,你想加入细胞A1A5,在每个值之间。


Excel 2016 Excel 2016

=TEXTJOIN(",",TRUE,A1:A5)

Older Excel Versions 较旧的Excel版本

You can easily combine without a delimiter: 无需分隔符即可轻松组合:

=CONCAT(A1:A5)

The equivalent to concat is the & text operator, which you could use like: 与concat等效的是&文本运算符,可以这样使用:

=A1 & A2 & A3 & A4 & A5

...for the same result as CONCAT . ...获得与CONCAT相同的结果。 To add the comma delimiter: 要添加逗号定界符:

=A1 & "," & A2 & "," & A3 & "," & A4 & "," & A5

Replacement for TEXTJOIN function 替换TEXTJOIN函数

Better yet, we could build our own version of TEXTJOIN , which I'll call TXTJOIN : 更好的是,我们可以构建自己的TEXTJOIN版本,我将其称为TXTJOIN

Function TxtJoin(delim As String, ignoreEmpty As Boolean, rg As Range) As String
    Dim c As Range
    For Each c In rg
        If Not ignoreEmpty Or Not IsEmpty(c) Then TxtJoin = TxtJoin & delim & c
    Next c
    If TxtJoin <> "" Then TxtJoin = Mid(TxtJoin, Len(delim) + 1)
End Function

The first parameter delim is the delimiter to place between each value, and can be one or more characters, or even special characters like CHAR(10) for a Line Feed (which would display in cells that have Word Wrap enabled.) 第一个参数delim是放置在每个值之间的定界符,可以是一个或多个字符,甚至是CHAR(10)特殊字符(如CHAR(10) (将在启用了自动换行的单元格中显示)。

The second parameter ignoreEmpty can be FALSE if you want blank cells included in the results, with a delimiter between each one, or TRUE to skip blank cells. 如果要在结果中包括空白单元格(在每个单元格之间使用定界符),则第二个参数ignoreEmpty可以为FALSE,或者为TRUE以跳过空白单元格。 (Obviously if the specified range has no blank cells then it doesn't matter what option you choose.) (显然,如果指定范围内没有空白单元格,那么选择哪种选项都没有关系。)

The third parameter is a range of cells. 第三个参数是一个单元格范围。 If there's more than one row or column specified, the formula will read right-to-left then top-to-bottom. 如果指定的行或列不止一个,则公式将从右到左,然后从上到下读取。

With our example, you'd use it like: 在我们的示例中,您将使用以下示例:

=TxtJoin(",",TRUE,A1:A5)

(This is the same usage as for Excel 2016's TEXTJOIN function.) (这与Excel 2016的TEXTJOIN函数的用法相同。)

This works in LibreOffice 5.4.3.2. 在LibreOffice 5.4.3.2。中有效。 If it does not work in your version, you may want to download and install a newer version. 如果它在您的版本中不起作用,则可能要下载并安装较新的版本。

=TEXTJOIN(",";;A1:A5)

By built-in function, I meant one automated by the software similar to the Text-to-columns function is built-in. 通过内置功能,我的意思是内置了一种类似于文本转列功能的软件。

I do not see such a feature. 我没有看到这样的功能。 It is not needed because spreadsheet functions work perfectly well. 不需要,因为电子表格功能可以很好地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM