您想学习如何在 Excel 中将数字转换为文本,以适当处理诸如输入和可视化大数值、显示前导零或阻止 Excel 将数字条目转换为日期等情况吗?请继续阅读!
尽管 Excel 主要用于处理数字并从原始数据集中创建可操作的见解,但它允许您将数字数据集转换为特殊格式,如日期、货币等。最常用的格式之一是数字到文本的转换,将小数转换为文本字符串。
例如,如果所有值都是数字格式,且条目长度超过 3 位,则您无法搜索某些数字组合,例如 500 在数据集中出现的次数。此时,将数据集转换为文本将有助于在数据集的单元格中搜索 500。还有更多这样的例子,其中给定数字的文本格式更有用。
以下是将数字转换为文本的各种方法,以便在 Excel 中方便地进行数据分析。
推荐:WordPress数据库搜索替换插件Better Search Replace Pro
使用撇号将数字转换为文本
如果您想在 Excel 中将一些数字转换为文本,可以使用这种快速手动方法。在这里,您只需在单元格中添加前导撇号即可将数值转换为文本字符串。

为此,选择相关的单元格并按下F2键进入单元格编辑模式。
单击值左侧的第一个字符并添加撇号符号。

HitEnter和 Excel 将立即自动将您的数字转换为文本。
您必须对数据集中的每个单元格分别重复此步骤。
您将在单元格中看到背景错误检查图标。您可以忽略它。

但是,如果 Excel 工作表用于专业会议或活动中的演示,则可以隐藏背景错误检查图标。只需单击单元格,然后单击右侧的黄色警告图标即可。
上下文菜单会打开,其中包含 6 个选项。单击最后一个选项,即“错误检查选项”。

Excel 选项对话框的公式设置应会显示出来。在此处,取消选中启用后台错误检查复选框,然后单击确定以保存更改。
使用“文本转列”将数字转换为文本
虽然“文本到列”工具允许您将分隔数据集(如逗号分隔值(CSV)、分号分隔值和制表符分隔值)拆分为多列,但它也可以用于将数值转换为文本。
当您必须将整列填充数字数据转换为文本字符串时,此方法特别合适。

转到源工作表并突出显示列中的数据集。现在,按Alt+ A+E调出“文本到列”向导。
选择“分隔”选项,然后单击“下一步”。

在对话框的下一个屏幕上,选择“分隔符”列下方的任意选项,然后单击“下一步”。

在列数据格式列下方,选择文本并单击完成按钮。

一旦完成所有步骤,Excel 就会将突出显示的数字转换为文本字符串。
如果您的 Excel 桌面应用程序上的后台错误检查处于活动状态,您应该会在数据集的单元格上看到绿色的错误检查图标。
使用“&”符号将数字转换为文本
在 Excel 中,您可以使用&( Shift+ 7) 运算符将文本字符串连接在一起。连接文本字符串时,如果您添加对数字单元格和文本单元格的引用,那么这样做同样有效。

假设您想使用此方法将列中的所有数字转换为文本,请转到源数据集列( A 列)右侧的空白列(B 列)的第一个单元格( B2 ) 。在那里,输入以下公式:
=""&A2

点击Enter即可完成数字到文本的转换。

现在,将填充柄沿列向下拖动,直到与B 列平行的源数据集中存在数据的最后一个单元格。
Excel 将快速复制该列所有单元格中第一个单元格的公式并计算生成文本字符串。
在这种方法中,您不会在转换后的单元格中看到背景错误检查图标。
使用数字格式化工具将数字转换为文本
如果包含数字的数据集的值不超过 11 个字符,则可以使用“主页”选项卡中的“数字格式化”工具将其转换为文本字符串。

突出显示目标数据集并转到“数字”块中的“常规”下拉菜单。单击它并从上下文菜单中选择“文本” 。

您应该将文本字符串放在同一列中。单元格中的条目应左对齐,并转换为文本值。
推荐:WooCommerce电子邮件定制器插件YayMail
使用“格式化单元格”工具将数字转换为文本
这是将海量数据集转换为文本字符串的另一种快速方法。

转到目标数据集并突出显示。
按Ctrl+1打开“设置单元格格式”对话框。
在那里,选择类别列下方的文本选项,然后单击确定。

这样,Excel 就会将数字转换为文本,而不会显示绿色的小错误检查图标。
使用 TEXT 函数将数字转换为文本
您还可以使用各种Excel公式从数值中获取文本字符串。TEXT函数就是其中之一。使用此公式,您还可以为输出值引入自定义格式。

在目标数据集上,突出显示第一个单元格并输入以下公式:
=TEXT(A2,"0")

按下Enter即可获取文本字符串。

现在您可以使用填充柄将相同的公式应用于列中的其余单元格。
要在文本字符串值中引入自定义格式,可以使用TEXT公式的以下变体:

=TEXT(123.25,"0.0")

=TEXT(123.25,"0.00")

=TEXT(D2,"$#,###,###.##")
使用 Power Query 将数字转换为文本
您还可以使用Power Query工具将导入或现有的数据集批量转换为文本字符串。如果您有 Excel 2010 或更高版本,则可以使用此方法。

如果您要从外部源导入大型数字数据集,您可以转到“数据”选项卡并单击“获取数据”以查找导入数据的各种选项。
在那里,将光标悬停在“从数据库”选项上,然后从“从 SQL”、“从 Microsoft Access ”、“从 Oracle”等选项中选择您的源。

对于工作表中已有的数据集,请突出显示它并单击“数据”选项卡中的“从表/范围”命令。单击“创建表”对话框中的“确定”以形成表。

您现在将在Power Query中看到您的数据集。

转到“添加列”选项卡并单击“自定义列”按钮。
在自定义列对话框中,在新列名称字段中键入名称。
在自定义列公式字段中,输入以下公式,然后单击确定:
Text.From([CC Numbers])
在上面的公式中,[CC Numbers]
根据您自己的数据集更改列名。

Power Query 将创建一个新列,其中包含相应数值的文本字符串。

现在,单击“文件”选项卡并选择“关闭并加载到”选项。

将显示“导入数据”对话框。在那里,选择现有工作表选项并突出显示您希望 Excel 从 Power Query 导入转换后的数据集的单元格。

您可以删除包含数值的冗余列作为文本字符串,或者您创建的自定义列包含您需要的值。
使用 Power Pivot 将数字转换为文本
Power Pivot是将大型数值数据集转换为文本字符串的另一种选择。在必须导入包含Excel 可以处理的超过 1,048,576 行的大数据集的情况下,应该使用 Power Pivot 。现在,您可以清理和转换数据集以将其导出到实际的 Excel 电子表格,该电子表格应在 Excel 的行数限制内。
如果您在 Excel 功能区菜单上没有看到 Power Pivot 选项卡,请阅读本文以将该工具添加到您的 Excel 桌面应用程序:
📒阅读更多:将 Power Pivot 添加到 Microsoft Excel 的 4 种方法

现在您已经获得了该工具,请突出显示您想要在 Power Pivot 中分析的数据集,然后单击Power Pivot选项卡内的“添加到数据模型”按钮。

您将看到“创建表”对话框。单击“确定”继续。

在Power Pivot窗口上,单击输入数据集的列标题。在“主页”选项卡上,单击“数据类型”按钮,然后在“格式”块中选择“整数” 。

现在,单击输入数据集相邻列的第一个单元格,并在其中输入以下数据分析表达式 (DAX)公式:
=FORMAT(Table5[CC Numbers],"0")

点击Enter。Power Pivot 将使用公式将左侧列中的所有数值数据转换为右侧列中的文本字符串。不要忘记根据您自己的数据集自定义公式。

突出显示 Power Pivot 列中的转换值并将其粘贴到 Excel 电子表格中。
推荐:WordPress卸载媒体插件Leopard
使用 Excel VBA 将数字转换为文本
如果您希望自动将数字转换为文本字符串,则可以使用Excel VBA。
下面的脚本可用于创建以交互方式处理任务的 VBA 宏:

Sub ConvertNumbersToText()
' Prompt the user to select a range of cells with numerical data
Dim SourceRange As Range
Set SourceRange = Application.InputBox("Select a range with numerical data", "Obtain Range Object", Type:=8)
' Prompt the user to select a range where to paste the converted data
Dim TargetRange As Range
Set TargetRange = Application.InputBox("Select a range where to paste the converted data", "Obtain Range Object", Type:=8)
' Check if the selected ranges have the same size
If SourceRange.Cells.Count TargetRange.Cells.Count Then
MsgBox "The source and target ranges must have the same size.", vbCritical
Exit Sub
End If
' Convert number formatting of input data to text format and paste the values in the designated cell range
Dim cell As Range
Dim i As Integer
For i = 1 To SourceRange.Cells.Count
Set cell = SourceRange.Cells(i)
TargetRange.Cells(i).NumberFormat = "@"
TargetRange.Cells(i).Value = Format(cell.Value, "0")
Next i
MsgBox "Conversion completed successfully.", vbInformation
End Sub

现在,当您执行宏时,您将看到一个对话框,允许您选择包含数值数据集的单元格范围作为输入。

接下来,您应该看到另一个允许您选择目标单元格范围的对话框。

最后,VBA 宏完成转换过程。转换完成后,您可能会看到绿色的错误检查图标。
要了解如何使用上述脚本创建 VBA 宏,请阅读以下文章:
📒阅读更多:如何使用在线找到的 VBA 代码
使用 Excel VBA 将货币符号转换为文本
您是否经常需要将货币数字符号转换为数字以便签发支票或进行银行业务?
然后,您可以使用以下 VBA 脚本通过单击以交互方式将数值货币金额转换为数字:

Sub ConvertNumbersToWords()
Dim rngInput As Range
Dim rngDestination As Range
Dim cell As Range
Dim inputCell As Variant
Dim outputCell As Range
' Prompt user to select input range
On Error Resume Next
Set rngInput = Application.InputBox("Select the range containing numerical values:", Type:=8)
On Error GoTo 0
' Exit if user cancels the input box
If rngInput Is Nothing Then
Exit Sub
End If
' Prompt user to select destination range
On Error Resume Next
Set rngDestination = Application.InputBox("Select the destination cell range:", Type:=8)
On Error GoTo 0
' Exit if user cancels the input box
If rngDestination Is Nothing Then
Exit Sub
End If
' Loop through each cell in input range
For Each cell In rngInput
' Check if cell contains a numerical value
If IsNumeric(cell.Value) Then
' Convert numerical value to words
inputCell = cell.Value
Set outputCell = rngDestination.Cells(cell.Row - rngInput.Row + 1, cell.Column - rngInput.Column + 1)
outputCell.Value = ConvertToWords(inputCell) & " dollars"
End If
Next cell
End Sub
Function ConvertToWords(ByVal number As Double) As String
Dim numText As String
Dim units As Variant, tens As Variant, teens As Variant
units = Array("", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine")
tens = Array("", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety")
teens = Array("eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen")
If number = 0 Then
ConvertToWords = "zero"
ElseIf number

首先,您需要选择输入数据集,如上所示。

然后,您还需要选择货币符号转换为文字的目的地。

上图为转换后的单词。
结论
就是这样!如果您希望在 Excel 中将数字转换为文本,这些就是您一直在寻找的方法。对于小规模的数字到文本的转换,您可以使用 Excel 应用程序界面命令,如文本到列、数字格式、设置单元格格式等。
对于大规模数据集的导入和转换,您应该选择 Power Query 和 Power Pivot。
最后,如果您希望自动化该过程,请使用本文提供的脚本创建 VBA 宏。