如何将Excel数字单元格值转换为单词

时间:2013-06-13 10:56:15

标签: excel excel-formula

我正在使用Microsoft Excel 2007,我的工作表中有一个数字列。

是否有任何解决方案可以将其转换为等效的单词?

我正在附上Excel Sheet的屏幕截图。

enter image description here

1 个答案:

答案 0 :(得分:4)

excel中没有内置公式,您必须添加vb脚本并将其永久保存在MS中。 Excel作为加载项安装。

  1. 按Alt + F11
  2. MENU :(工具条)插入模块
  3. 复制并粘贴以下代码

  4. Option Explicit
    
    Public Numbers As Variant, Tens As Variant
    
    Sub SetNums()
        Numbers = Array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen")
        Tens = Array("", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety")
    End Sub
    
    Function WordNum(MyNumber As Double) As String
        Dim DecimalPosition As Integer, ValNo As Variant, StrNo As String
        Dim NumStr As String, n As Integer, Temp1 As String, Temp2 As String
        ' This macro was written by Chris Mead - www.MeadInKent.co.uk
        If Abs(MyNumber) > 999999999 Then
            WordNum = "Value too large"
            Exit Function
        End If
        SetNums
        ' String representation of amount (excl decimals)
        NumStr = Right("000000000" & Trim(Str(Int(Abs(MyNumber)))), 9)
        ValNo = Array(0, Val(Mid(NumStr, 1, 3)), Val(Mid(NumStr, 4, 3)), Val(Mid(NumStr, 7, 3)))
        For n = 3 To 1 Step -1    'analyse the absolute number as 3 sets of 3 digits
            StrNo = Format(ValNo(n), "000")
            If ValNo(n) > 0 Then
                Temp1 = GetTens(Val(Right(StrNo, 2)))
                If Left(StrNo, 1) <> "0" Then
                    Temp2 = Numbers(Val(Left(StrNo, 1))) & " hundred"
                    If Temp1 <> "" Then Temp2 = Temp2 & " and "
                Else
                    Temp2 = ""
                End If
                If n = 3 Then
                    If Temp2 = "" And ValNo(1) + ValNo(2) > 0 Then Temp2 = "and "
                    WordNum = Trim(Temp2 & Temp1)
                End If
                If n = 2 Then WordNum = Trim(Temp2 & Temp1 & " thousand " & WordNum)
                If n = 1 Then WordNum = Trim(Temp2 & Temp1 & " million " & WordNum)
            End If
        Next n
        NumStr = Trim(Str(Abs(MyNumber)))
        ' Values after the decimal place
        DecimalPosition = InStr(NumStr, ".")
        Numbers(0) = "Zero"
        If DecimalPosition > 0 And DecimalPosition < Len(NumStr) Then
            Temp1 = " point"
            For n = DecimalPosition + 1 To Len(NumStr)
                Temp1 = Temp1 & " " & Numbers(Val(Mid(NumStr, n, 1)))
            Next n
            WordNum = WordNum & Temp1
        End If
        If Len(WordNum) = 0 Or Left(WordNum, 2) = " p" Then
            WordNum = "Zero" & WordNum
        End If
    End Function
    
    Function GetTens(TensNum As Integer) As String
    ' Converts a number from 0 to 99 into text.
        If TensNum <= 19 Then
            GetTens = Numbers(TensNum)
        Else
            Dim MyNo As String
            MyNo = Format(TensNum, "00")
            GetTens = Tens(Val(Left(MyNo, 1))) & " " & Numbers(Val(Right(MyNo, 1)))
        End If
    End Function
    

    在此之后,从文件菜单中选择保存书,从下一个菜单中选择 “Excel 97-2003加载项(* .xla)

    它将另存为Excel加载项。在将Ms.Office安装到该机器之前可以使用。

    现在打开任何单元格类型=WordNum(<your numeric value or cell reference>)

    中的任何Excel文件

    你会看到一个等价于数值的单词。

    此代码段摘自:http://en.kioskea.net/forum/affich-267274-how-to-convert-number-into-text-in-excel