现在遇到一个问题,文本框里姓名的地方可能有中文姓名,现在输入中文姓名,保存到数据库中后,姓名在表中是用unicode得编码存放的,在 显示 到页面上也没有问题,现在是还要打印到Excel中,结果就有问题了。
打印出来的数据是Unicode码,而不是中文。
如:“婷嫗“ 在Excel中显示“婷嫗”
解决方案:
Function uni2gb(str)
Dim tmp,tmpstr,i
tmpstr = ""
For i = 1 To Len(str)
tmp=Mid(str,i,1)
If tmp = "&" And Mid(str,i + 1,1) = "#" And Mid(str,i + 7,1) = ";" And IsNumeric(Mid(str,i + 2,5)) = True Then
tmpstr = tmpstr & ChrW(Mid(str,i + 2,5))
i = i + 7
Else
tmpstr = tmpstr & tmp
End If
Next
uni2gb=tmpstr
End Function
Dim tmp,tmpstr,i
tmpstr = ""
For i = 1 To Len(str)
tmp=Mid(str,i,1)
If tmp = "&" And Mid(str,i + 1,1) = "#" And Mid(str,i + 7,1) = ";" And IsNumeric(Mid(str,i + 2,5)) = True Then
tmpstr = tmpstr & ChrW(Mid(str,i + 2,5))
i = i + 7
Else
tmpstr = tmpstr & tmp
End If
Next
uni2gb=tmpstr
End Function