首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Excel中快速定义单词列表

如何在Excel中快速定义单词列表
EN

Stack Overflow用户
提问于 2015-07-20 05:25:26
回答 1查看 7.7K关注 0票数 1

我在A栏中有一大串单词,我想使用excel来查找google或bing对每个单词的大量定义。Excel在研究中有一个内置的函数,它将显示bing的定义,但是您必须手动完成每个单词的操作。

我尝试了下面链接中列出的方法,但是它是旧的,函数一直返回错误的“公式中使用的值是错误的数据类型”在VBA中查找单词的英文定义

如果有人知道一个程序或网站,将查找谷歌的定义一大串词,这也是有帮助的。

EN

回答 1

Stack Overflow用户

发布于 2015-07-20 23:26:54

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

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

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31509327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档