Excel 2010 将单元格内容中的科学计数方程式转换为十进制表示

Excel 2010 Convert scientific notation equation in cell contents into decimal representation

我有一个电子表格,里面有将近 400 个方程式。电子表格的创建者 copy/pasted 来自其他来源的值。有几个在其可变系数中使用科学记数法。我正在寻找一种将它们转换为十进制表示法的方法,以便我可以将它们存储在数据库中并使用动态 sql.

执行

这是我的例子

y = -6E-05x4 + 0.0272x3 - 1.4546x2 - 17.743x + 8137.3

我想要这样

y = -0.00006x^4 + 0.0272x^3 - 1.4546x^2 - 17.743x + 8137.3

方程列被 Excel 视为 "General" 列。我尝试更改列类型,希望 Excel 能够识别该函数并转换系数,但它不会。我试图不必手动转换科学记数法来重写所有这些方程式。我也愿意使用第 3 方软件将科学计数法转换为十进制表示法。

您可以使用 VBA UDF(用户定义函数)执行此操作。 我

  • 使用正则表达式解析以科学记数法输入的任何数字
  • 将它们转换为十进制数
  • 将原值替换为十进制值

大于 10^28 的值将保持不变。小于 10^-28 的值将被转换为零 (0)。


Option Explicit
Function ConvertToDecimal(S As String) As String
    Dim RE As Object, MC As Object, M As Object
    'Regex pattern to extract Scientific numbers
    Const sPat As String = "[-+]?\d+(\.\d+)?[Ee][+-]\d+"
    Dim sRepl As String, I As Long

Set RE = CreateObject("vbscript.regexp")
With RE
    .Global = True
    .Pattern = sPat
    If .Test(S) = True Then
        Set MC = .Execute(S)
            sRepl = S
            For Each M In MC
                On Error Resume Next
                    sRepl = Replace(sRepl, M, Format(CDec(M), "#,##0.0" & WorksheetFunction.Rept("#", 30)), 1, 1)
                    Select Case Err.Number
                        Case 6 'Overflow
                        'do nothing. sRepl is unchanged
                        Case Is <> 0
                            Debug.Print Err.Number, Err.Description
                            Stop 'stop to debug
                    End Select
                On Error GoTo 0
            Next M
    End If
End With

ConvertToDecimal = sRepl

End Function