|
跟学习下。谢谢老师!
Public Function EnToCh(rng As String, z)
Dim xml
Dim URL$, EngSentence$
Set xml = CreateObject("MSXML2.XMLHTTP")
'EngSentence = URLEncodePlus(rng.Text)
'url = "https://translate.google.cn/m?hl=en&sl=enN&tl=zh-CN&ie=UTF-8&prev=_m&q=" & EngSentence
If z = 1 Then
URL = "https://translate.google.cn/m?hl=en&sl=enN&tl=zh-CN&ie=UTF-8&prev=_m&q=" & rng
Else
URL = "https://translate.google.cn/m?hl=en&sl=zh-CN&tl=enN&ie=UTF-8&prev=_m&q=" & GetURL(rng)
End If
With xml
.Open "GET", URL, False
.send
If InStr(.responseText, "<div dir=""ltr"" class=""t0"">") > 0 Then
EnToCh = Split(Split(.responseText, "<div dir=""ltr"" class=""t0"">")(1), "</div><")(0)
End If
End With
End Function
Function GetURL$(txt$)
'Dim a() As Byte
'a = StrConv(txt, vbFromUnicode, &H804)
For i = 1 To Len(txt)
txt1 = Mid(txt, i, 1)
If Abs(Asc(txt1)) < 128 Then
GetURL = GetURL & txt1
Else
GetURL1 = Application.Hex2Bin(left(Hex(AscW(txt1)), 2), 8)
GetURL1 = GetURL1 & Application.Hex2Bin(right(Hex(AscW(txt1)), 2), 8)
GetURL1 = Application.Replace(Application.Replace(GetURL1, 11, , 10), 5, , 10)
GetURL2 = "%E" & Application.Bin2Hex(left(GetURL1, 4))
GetURL2 = GetURL2 & "%" & Application.Bin2Hex(Mid$(GetURL1, 5, 8))
GetURL2 = GetURL2 & "%" & Application.Bin2Hex(Mid$(GetURL1, 13, 8))
GetURL = GetURL & GetURL2
End If
Next
End Function |
评分
-
2
查看全部评分
-
|