1. 程式人生 > 其它 >Excel URL解碼函式的使用

Excel URL解碼函式的使用

技術標籤:其他大資料

url解碼函式(亂碼編譯成中文)

Function URLDecode(ByVal strIn)

       URLDecode = ""

       Dim sl: sl = 1

       Dim tl: tl = 1

       Dim key: key = "%"

       Dim kl: kl = Len(key)

       sl = InStr(sl, strIn, key, 1)

       Do While sl > 0

          If (tl = 1 And sl <
> 1) Or tl < sl Then URLDecode = URLDecode & Mid(strIn, tl, sl - tl) End If Dim hh, hi, hl Dim a Select Case UCase(Mid(strIn, sl + kl, 1)) Case "U" 'Unicode URLEncode a = Mid(strIn, sl + kl + 1, 4) URLDecode = URLDecode & ChrW("&H" & a) sl = sl + 6 Case "E" '
UTF-8 URLEncode hh = Mid(strIn, sl + kl, 2) a = Int("&H" & hh) 'ascii碼 If Abs(a) < 128 Then sl = sl + 3 URLDecode = URLDecode & Chr(a) Else hi = Mid(strIn, sl + 3 + kl, 2) hl = Mid(strIn, sl + 6 + kl, 2) a = ("&H" & hh And &HF) * 2 ^ 12 Or ("&H" & hi And &H3F) * 2 ^ 6 Or ("&H" & hl And &H3F) If a < 0 Then a = a + 65536 URLDecode = URLDecode & ChrW(a) sl = sl + 9 End If Case Else '
Asc URLEncode hh = Mid(strIn, sl + kl, 2) '高位 a = Int("&H" & hh) 'ascii碼 If Abs(a) < 128 Then sl = sl + 3 Else hi = Mid(strIn, sl + 3 + kl, 2) '低位 a = Int("&H" & hh & hi) '非ascii碼 sl = sl + 6 End If URLDecode = URLDecode & Chr(a) End Select tl = sl sl = InStr(sl, strIn, key, 1) Loop URLDecode = URLDecode & Mid(strIn, tl) End Function

如何使用excel自定義函式

1.開啟excel

2.ALT+F11,會開啟VB視窗

3.找到“插入”,選擇插入模組

4.把以上程式碼分別複製到不同模組,然後儲存。

5.關掉VB視窗,直接在頂部的輸入框輸入函式名字即可