【问题标题】:How to Quickly Define a List of Words in Excel如何在 Excel 中快速定义单词列表
【发布时间】:2015-07-20 05:25:26
【问题描述】:

我在 A 列中有大量单词。我想使用 excel 批量查找每个单词的 google 或 bing 定义。 Excel 有一个正在研究的内置函数,它会向您显示 bing 定义,但您必须手动为每个单词执行此操作。

我尝试了下面链接中列出的方法,但它是旧的,并且函数不断返回错误“公式中使用的值是错误的数据类型”Finding the English definition of a word in VBA

如果有人知道一个程序或网站,该程序或网站会在 google 定义中查找大量单词,这些单词也会很有帮助。

【问题讨论】:

  • 在 Excel 2013 中有许多交互式工作表公式。您可以使用WEBSERVICE() 调用多个 API。我强烈推荐 Oxford Dictionaries API,Google Dict API deprecated see link.

标签: vba excel dictionary


【解决方案1】:

应该有比我下面的代码更有效的方法来做到这一点。它使用来自Dictionary.com 的服务。

您可以将它用作工作表中的函数,假设您在 A1 中有“披萨”,然后在 A2 中,您使用=DictReference(A1) 来显示定义。但是我只对其进行了编码以返回第一个定义。

Option Explicit

Const URL_SEARCH = "http://dictionary.reference.com/browse/<WORD>?s=t"

Function DictReference(ByVal SearchWord As Variant) As String
    On Error Resume Next
    Dim sWord As String, sTxt As String
    sWord = CStr(SearchWord)
    With CreateObject("WinHttp.WinHttpRequest.5.1")
        .Open "GET", Replace(URL_SEARCH, "<WORD>", sWord), False
        .Send
        If .Status = 200 Then
            sTxt = StrConv(.ResponseBody, vbUnicode)
            ' The definition of the searched word is in div class "def-content"
            sTxt = Split(sTxt, "<div class=""def-content"">")(1)
            sTxt = Split(sTxt, "</div>")(0)
            ' Remove all unneccessary whitespaces
            sTxt = Replace(sTxt, vbLf, "")
            sTxt = Replace(sTxt, vbCr, "")
            sTxt = Replace(sTxt, vbCrLf, "")
            sTxt = Trim(sTxt)
            ' Remove any HTML codes within
            sTxt = StripHTML(sTxt)
        Else
            sTxt = "WinHttpRequest Error. Status: " & .Status
        End If
    End With
    If Err.Number <> 0 Then sTxt = "Err " & Err.Number & ":" & Err.Description
    DictReference = sTxt
End Function

Private Function StripHTML(ByVal sHTML As String) As String
    Dim sTmp As String, a As Long, b As Long
    sTmp = sHTML
    Do Until InStr(1, sTmp, "<", vbTextCompare) = 0
        a = InStr(1, sTmp, "<", vbTextCompare) - 1
        b = InStr(a, sTmp, ">", vbTextCompare) + 1
        sTmp = Left(sTmp, a) & Mid(sTmp, b)
    Loop
    StripHTML = sTmp
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-09
    • 2020-09-23
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多