excel提取汉字拼音首字母

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了excel提取汉字拼音首字母相关的知识,希望对你有一定的参考价值。

本文转载:http://jingyan.baidu.com/article/63acb44adca44461fcc17e85.html

利用Excel表格中的宏,轻松提取首字母

方法/步骤

1.启动Excel 2003(其它版本请仿照操作),打开相应的工作表;

2.执行“工具→宏→Visual Basic编辑器”命令(或者直接按“Alt+F11”组合键),进入Visual Basic编辑状态;

3.执行“插入→模块”命令,插入一个新模块。再双击插入的模块,进入模块代码编辑状态;

4.将代码输入其中;

Function pinyin(p As String) As String

i = Asc(p)

Select Case i

Case -20319 To -20284: pinyin = "A"

Case -20283 To -19776: pinyin = "B"

Case -19775 To -19219: pinyin = "C"

Case -19218 To -18711: pinyin = "D"

Case -18710 To -18527: pinyin = "E"

Case -18526 To -18240: pinyin = "F"

Case -18239 To -17923: pinyin = "G"

Case -17922 To -17418: pinyin = "H"

Case -17417 To -16475: pinyin = "J"

Case -16474 To -16213: pinyin = "K"

Case -16212 To -15641: pinyin = "L"

Case -15640 To -15166: pinyin = "M"

Case -15165 To -14923: pinyin = "N"

Case -14922 To -14915: pinyin = "O"

Case -14914 To -14631: pinyin = "P"

Case -14630 To -14150: pinyin = "Q"

Case -14149 To -14091: pinyin = "R"

Case -14090 To -13319: pinyin = "S"

Case -13318 To -12839: pinyin = "T"

Case -12838 To -12557: pinyin = "W"

Case -12556 To -11848: pinyin = "X"

Case -11847 To -11056: pinyin = "Y"

Case -11055 To -2050: pinyin = "Z"

Case Else: pinyin = p

End Select

End Function

Function getpy(str)

For i = 1 To Len(str)

getpy = getpy & pinyin(Mid(str, i, 1))

Next i

End Function

5.代码输入完成后,关闭Visual Basic编辑窗口,返回Excel编辑状态;

6.自定义函数就可以用了,如:选中A2单元格,输入公式:=getpy(A2)。

以上是关于excel提取汉字拼音首字母的主要内容,如果未能解决你的问题,请参考以下文章

JAVA 汉字首字母排序

算法笔记_232:提取拼音首字母(Java)

js中如何根据汉字生成拼音首字母

怎样把其中的汉字提取出来呀,求Python大佬解答

获取整条字符串所有汉字拼音首字母的函数

java怎么根据汉字获取字的拼音首字母