1、一、 汉字转为 URL 编码在 excel 中填加宏代码Function EncodeUrl_ANSI(sStr$) As StringDim iAscii%, sEncode$, i&, sResult$For i = 1 To Len(sStr)sEncode = Mid$(sStr, i, 1)iAscii = Asc(sEncode)Select Case iAsciiCase 0 To 255 127 单字节Select Case sEncodeCase “0“ To “9“, “A“ To “Z“, “a“ To “z“ ,“-“,“_“ 添加其他非转义字符这些字符不进行 转义 。
2、Case Else 其他字符都要 转义 。sEncode = Hex(iAscii)sEncode = “%“ & Right(sEncode, 2)End SelectCase Else 双字节sEncode = Hex(iAscii)sEncode = “%“ & Left(sEncode, 2) & “%“ & Right(sEncode, 2)End SelectsResult = sResult & sEncodeNextEncodeUrl_ANSI = sResultEnd Function保存后,在表格中使用”= EncodeUrl_ANSI”调用。二、 URL 编码转汉字在 e
3、xcel 宏加新建模块加代码:Function URLDecode(strURL)Dim iIf InStr(strURL, “%“) = 0 ThenURLDecode = strURLExit FunctionEnd IfFor i = 1 To Len(strURL)If Mid(strURL, i, 1) = “%“ ThenIf CInt(“&H“ & Mid(strURL, i + 1, 2) 127 ThenURLDecode = URLDecode & Chr(CInt(“&H“ & Mid(strURL, i + 1, 2) & Mid(strURL, i + 4, 2)i = i + 5ElseURLDecode = URLDecode & Chr(CInt(“&H“ & Mid(strURL, i + 1, 2)i = i + 2End IfElseURLDecode = URLDecode & Mid(strURL, i, 1)End IfNextEnd Function在 excel 表格中调用” =URLDecode”就可以完全实现了。