将URL格式的内容转换为Microsoft EXCEL中的纯文本

tvokkenx  于 2023-06-25  发布在  其他
关注(0)|答案(5)|浏览(191)

我有URL格式的内容,通常我只是手动翻译1-由-1米,但这次有成千上万的条目,例如:-

%E5%B7%B2%E4%BB%8E%E5%B8%90%E6%88%B7zh*****%40outlook.com%E5%88%A0%E9%99%A48618650533*%E3%80%82%E4%B8%8D%E6%98%AF%E4%BD%A0%EF%BC%9F
%E7%AE%A1%E7%90%86%E9%A2%84%E8%AE%A2%0A
https%3A%2F%2Faccount.live.com%2Fa
OTO+GLOBAL+Certification+No%3A%5B6198%5D
Deluxe+Room+-1+%E9%97%B4%0A
Ihre+Agoda+Buchung+Nr.+77083713+ist+bes %C3%A4tigt%21+Verwalten+Sie+Ihre+B
%E6%82%A8%E7%9A%84Agoda%E8%AE%A2%E5%8D%95%2877083753%29%E5%B7%B2%E7%A%AE%E8%AE%A4%EF%BC%81+%E4%BD%BF%E7%94%A8%E6%88%91%E4%BB%AC%E7%9A%84%E5%85%8D%E8%B4%B9%E5%AE%A2%E6%88%B7%E7%AB%AFhttp%3A%2F%2Fapp-agoda.com%2FGetTheApp%EF%BC%8C%E8%BD%BB%E6%9D%BE

是否有任何方法可以将所有这些内容转换为Microsoft Excel中的纯英语文本?
问候

yi0zb3m4

yi0zb3m41#

没有内置函数来处理此问题,但可以使用自定义函数,安装第三方加载项或使用替代命令:

使用自定义VBA函数

来源:http://www.freevbcode.com/ShowCode.asp?ID=1512

Public Function URLDecode(StringToDecode As String) As String

Dim TempAns As String
Dim CurChr As Integer

CurChr = 1

Do Until CurChr - 1 = Len(StringToDecode)
  Select Case Mid(StringToDecode, CurChr, 1)
    Case "+"
      TempAns = TempAns & " "
    Case "%"
      TempAns = TempAns & Chr(Val("&h" & _
         Mid(StringToDecode, CurChr + 1, 2)))
       CurChr = CurChr + 2
    Case Else
      TempAns = TempAns & Mid(StringToDecode, CurChr, 1)
  End Select

CurChr = CurChr + 1
Loop

URLDecode = TempAns
End Function

支持第三方插件

来源:SeoTools(需要安装)

=UrlDecode(your_string_here)

使用替换命令

来源:https://searchmarketingcorner.wordpress.com/2013/03/27/creating-an-excel-formula-to-encode-or-unencode-urls/
将下面的公式粘贴到单元格的右侧,以便对该单元格的内容进行URL解码

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(CELL_TO_BE_DECODED,"%3F","?"),"%20"," "),"%25", "%"),"%26","&"),"%3D","="),"%7B","{"),"%7D","}"),"%5B","["),"%5D","]")

或者对于GUID,为破折号再添加一个SUBSTITUTE。

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(CELL_TO_BE_DECODED,"%3F","?"),"%20"," "),"%25", "%"),"%26","&"),"%3D","="),"%7B","{"),"%7D","}"),"%5B","["),"%5D","]"),"%2D","-")

为了完整起见,这里是URL编码的反向公式。这与URL编码公式相同,但new_textold_text的位置互换。

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(CELL_TO_BE_ENCODED,"?","%3F")," ","%20"),"%","%25"),"&","%26"),"=","%3D"),"{","%7B"),"}","%7D"),"[","%5B"),"]","%5D")

或者对于GUID,为破折号再添加一个SUBSTITUTE。

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(CELL_TO_BE_ENCODED,"?","%3F")," ","%20"),"%","%25"),"&","%26"),"=","%3D"),"{","%7B"),"}","%7D"),"[","%5B"),"]","%5D"),"-","%2D")
mctunoxg

mctunoxg2#

下面是一个实际工作的用户定义函数(UDF)。
在标准代码模块中,放置以下例程:

Public Function URLDecode(url$) As String
    With CreateObject("ScriptControl")
        .Language = "JavaScript"
        URLDecode = .Eval("unescape(""" & url & """)")
    End With
End Function

现在,您可以从工作表调用它,就像内置的Excel函数一样。
例如,如果编码的URL文本位于单元格A1中,则可以在单元格B1中输入以下公式:

=URLDecode(A1)

就是这样。完全解码的URL现在在单元格B1中。
请注意,这是真实的的交易。这不是试图取代几个字符。这通过Microsoft Script Control使用JavaScript的全部功能来完全解码URL。

vhmi4jdf

vhmi4jdf3#

下面添加了对URL中逗号的解码。只需要为%2C添加一个SUBSTITUTE。这只是添加到卡洛斯的职位从4年前。

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(CELL_TO_BE_DECODED,"%3F","?"),"%20"," "),"%25", "%"),"%26","&"),"%3D","="),"%7B","{"),"%7D","}"),"%5B","["),"%5D","]"),"%2D","-"),"%2C",",")
p5fdfcr1

p5fdfcr14#

您可以在没有VBA的情况下使用数组公式来执行此操作。如果A1是要解码的单元格,请输入此公式,然后按Ctrl-Shift-Enter键:

=TEXTJOIN("", FALSE,
    MID(A1,
        FIND("*",
            SUBSTITUTE("%DD"&A1,"%","*",  ROW(INDIRECT("1:"&LEN(A1)-LEN(SUBSTITUTE(A1,"%",""))+1))   )
        ),
        FIND("*",
            SUBSTITUTE(A1&"%","%","*",    ROW(INDIRECT("1:"&LEN(A1)-LEN(SUBSTITUTE(A1,"%",""))+1))   )
        ) - FIND("*",
            SUBSTITUTE("%EE"&A1,"%","*",  ROW(INDIRECT("1:"&LEN(A1)-LEN(SUBSTITUTE(A1,"%",""))+1))   )
        )
    ) & IFERROR(CHAR(HEX2DEC(MID(A1,
        FIND("*",
            SUBSTITUTE(A1&"%","%","*",    ROW(INDIRECT("1:"&LEN(A1)-LEN(SUBSTITUTE(A1,"%",""))+1))   )
        )+1,
       2
    ))),"")
 )

如果你不按Ctrl-Shift-Enter键,它将无法工作。

6ss1mwsb

6ss1mwsb5#

现在可以使用递归lambda函数来创建简洁的URL解码器函数。
打开名称管理器并将“DECODEURL”定义为:

=LAMBDA(encodedUrl,
  LET(
    length, LEN(encodedUrl),
    head, LEFT(encodedUrl, 1),
    IF(length < 3,
      encodedUrl,
      IF(head = "%",
        CONCAT(
          CHAR(HEX2DEC(MID(encodedUrl, 2, 2))),
          DECODEURL(RIGHT(encodedUrl, length - 3))
        ),
        CONCAT(
          head,
          DECODEURL(RIGHT(encodedUrl, length - 1))
        )
      )
    )
  )
)

然后,您可以简单地使用=DECODEURL(CELL_TO_BE_DECODED)调用该函数。

备注

1.没有输入验证,因此如果URL中存在无效字符串(例如%A%),则此函数将返回#NUM!
1.确保函数定义中没有制表符,因为这将阻止Excel将其识别为有效公式。

相关问题