Excel 取得汉字拼音首字母

转载 2015年11月18日 10:06:48

最近写代码需要用到将一些汉字的首字母作为枚举型的要求,网上看到了这个方法,在Excel VB脚本中使用,在这记录下:

下面是一个VBA自定义函数,按ALT+F11,插入模块,在右面窗口中粘贴下面代码。
若B10内容为 中国航天6号a,则在某空白格中输入:=hztopy(B10) 即可
Function hztopy(hzpy As String) As String
Dim hzstring As String, pystring As String
Dim hzpysum As Integer, hzi As Integer, hzpyhex As Integer
hzstring = Trim(hzpy)
hzpysum = Len(Trim(hzstring))
pystring = ""
For hzi = 1 To hzpysum
hzpyhex = "&H" + Hex(Asc(Mid(hzstring, hzi, 1)))
Select Case hzpyhex
Case &HB0A1 To &HB0C4: pystring = pystring + "A"
Case &HB0C5 To &HB2C0: pystring = pystring + "B"
Case &HB2C1 To &HB4ED: pystring = pystring + "C"
Case &HB4EE To &HB6E9: pystring = pystring + "D"
Case &HB6EA To &HB7A1: pystring = pystring + "E"
Case &HB7A2 To &HB8C0: pystring = pystring + "F"
Case &HB8C1 To &HB9FD: pystring = pystring + "G"
Case &HB9FE To &HBBF6: pystring = pystring + "H"
Case &HBBF7 To &HBFA5: pystring = pystring + "J"
Case &HBFA6 To &HC0AB: pystring = pystring + "K"
Case &HC0AC To &HC2E7: pystring = pystring + "L"
Case &HC2E8 To &HC4C2: pystring = pystring + "M"
Case &HC4C3 To &HC5B5: pystring = pystring + "N"
Case &HC5B6 To &HC5BD: pystring = pystring + "O"
Case &HC5BE To &HC6D9: pystring = pystring + "P"
Case &HC6DA To &HC8BA: pystring = pystring + "Q"
Case &HC8BB To &HC8F5: pystring = pystring + "R"
Case &HC8F6 To &HCBF9: pystring = pystring + "S"
Case &HCBFA To &HCDD9: pystring = pystring + "T"
Case &HEDC5: pystring = pystring + "T"
Case &HCDDA To &HCEF3: pystring = pystring + "W"
Case &HCEF4 To &HD1B8: pystring = pystring + "X"
Case &HD1B9 To &HD4D0: pystring = pystring + "Y"
Case &HD4D1 To &HD7F9: pystring = pystring + "Z"
Case Else
pystring = pystring + Mid(hzstring, hzi, 1)
End Select
Next
hztopy = pystring
End Function

相关文章推荐

如何获得汉字拼音的首字母序列

package wkx; public class TestName { private static String[] strChineseCharList = { "A阿啊锕嗄厑哎哀唉埃...

PostgreSQL获取汉字拼音首字母函数

本文转自http://blog.qdac.cc/?p=1281 --© 2014,swish,原版首发:http://blog.qdac.cc/?p=1281,自由使用,保留版权 CREATE OR...
  • vnsoft
  • vnsoft
  • 2015年10月17日 21:38
  • 1283

汉字拼音首字母查询

  • 2015年12月15日 00:57
  • 112KB
  • 下载

使用ORACLE函数实现按汉字拼音首字母查询

from:http://www.codesky.net/article/201010/141945.html CREATE OR REPLACE FUNCTION F_TRANS_PINYIN_CA...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Excel 取得汉字拼音首字母
举报原因:
原因补充:

(最多只允许输入30个字)