excel中如何实现提取汉字的拼音首字母

如题所述

步骤:
第一步、启动Excel 2003(其它版本请仿照操作),打开相应的工作表;
第二步、执行“工具→宏→Visual Basic编辑器”命令(或者直接按“Alt+F11”组合键),进入Visual Basic编辑状态;
第三步、执行“插入→模块”命令,插入一个新模块。再双击插入的模块,进入模块代码编辑状态;
第四步、将代码输入其中;
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
第五步、代码输入完成后,关闭Visual Basic编辑窗口,返回Excel编辑状态;
第六步、自定义函数就可以用了,如:选中A2单元格,输入公式:=getpy(A2)。
温馨提示:内容为网友见解,仅供参考
第1个回答  2015-09-29
分两步
1、取得拼音
得用到VBA
打开Excel->工具->宏->Viaual Basic编辑器

在弹出来的窗口中对着VBAproject点右键->插入->模块
下面会出现一个名为"模块1",点击
在右边的空白栏中粘贴以下内容:

Function getpychar(char)
tmp = 65536 + Asc(char)
If (tmp >= 45217 And tmp <= 45252) Then
getpychar = "A"
ElseIf (tmp >= 45253 And tmp <= 45760) Then
getpychar = "B"
ElseIf (tmp >= 45761 And tmp <= 46317) Then
getpychar = "C"
ElseIf (tmp >= 46318 And tmp <= 46825) Then
getpychar = "D"
ElseIf (tmp >= 46826 And tmp <= 47009) Then
getpychar = "E"
ElseIf (tmp >= 47010 And tmp <= 47296) Then
getpychar = "F"
ElseIf (tmp >= 47297 And tmp <= 47613) Then
getpychar = "G"
ElseIf (tmp >= 47614 And tmp <= 48118) Then
getpychar = "H"
ElseIf (tmp >= 48119 And tmp <= 49061) Then
getpychar = "J"
ElseIf (tmp >= 49062 And tmp <= 49323) Then
getpychar = "K"
ElseIf (tmp >= 49324 And tmp <= 49895) Then
getpychar = "L"
ElseIf (tmp >= 49896 And tmp <= 50370) Then
getpychar = "M"
ElseIf (tmp >= 50371 And tmp <= 50613) Then
getpychar = "N"
ElseIf (tmp >= 50614 And tmp <= 50621) Then
getpychar = "O"
ElseIf (tmp >= 50622 And tmp <= 50905) Then
getpychar = "P"
ElseIf (tmp >= 50906 And tmp <= 51386) Then
getpychar = "Q"
ElseIf (tmp >= 51387 And tmp <= 51445) Then
getpychar = "R"
ElseIf (tmp >= 51446 And tmp <= 52217) Then
getpychar = "S"
ElseIf (tmp >= 52218 And tmp <= 52697) Then
getpychar = "T"
ElseIf (tmp >= 52698 And tmp <= 52979) Then
getpychar = "W"
ElseIf (tmp >= 52980 And tmp <= 53640) Then
getpychar = "X"
ElseIf (tmp >= 53689 And tmp <= 54480) Then
getpychar = "Y"
ElseIf (tmp >= 54481 And tmp <= 62289) Then
getpychar = "Z"
Else '如果不是中文,则不处理
getpychar = char
End If
End Function
Function getpy(str)
For i = 1 To Len(str)
getpy = getpy & getpychar(Mid(str, i, 1))
Next i
End Function

按ALT+F11回到EXCEL

2、如果你的表如下
A B C D
1 姓名 出生年月 工作时间
2 刘德华 1965 1982

在D2单元格输入公式
=getpy(A2)&right(B2,2)&right(C2,2)
第2个回答  2014-11-04
后面又提的问题,手工做只需选中ZGHT6Ha这一列复制,再另一列选择性粘贴->数值,再改就行了。

下面是一个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本回答被提问者和网友采纳

如何提取电子表格里的汉字首字母?
1、我们需要仅提取汉字首字母,我们首先点击方方格子选项卡。2、点击文本这一选项卡。3、找到汉字转拼音选项并点击。4、出现对话框,我们选好我们的汉字区域,勾选好仅提取首字母之后点击确定。5、可以看到我们的公式设置完成啦点击确定。6、可以看到我们这一操作就完成。

Excel怎么提取汉字的首字母
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...

Excel中如何获取文字拼音
选择“复制”按钮,粘贴到word文档,选择“只粘贴文本”。打开并进入“word”中,选中文字,点击右上方的“拼音指南”。在窗口中点击“确定”,文字上方就有了拼音,复制选中的文字。在Excel中右键选择“保留原格式粘贴”,输入“=PHONETIC(G9)”。敲下回车键,便提取文字上的拼音,下拉即可得到所有汉字...

怎么从excel里提取汉字的拼音首字母呢?
1. 在Excel中输入姓名数据。2. 在另一个单元格中使用我们之前提到的汉字转拼音函数,将姓名转化为拼音。3. 使用Excel的LEFT函数,提取拼音的第一个字母。LEFT函数可以提取一个文本字符串的左侧部分字符。例如,如果我们的姓名是“张三”,我们将这个姓名转化为拼音“Zhang San”,...

如何提取汉字首字母
1、首先打开excel表,将员工的姓名输入到表中。2、然后用鼠标选择所有需要提取字母的名字,通过Ctrl+C复制。3、再打开word文档,将刚刚复制好的姓名,无格式粘贴到word中。鼠标全选姓名,在顶部开始菜单中找到拼音指南并鼠标点击。4、弹出拼音指南对话框后,再点击确定按钮,就可以看到word文档中的姓名上方...

怎么将表格中文字提取首字母
提取表格中文字的首字母是一项常用的功能,尤其是在需要快速处理大量文本数据时。通过Excel自定义函数和步骤,可以轻松实现这一目标。首先,确保关闭代码窗口,回到Excel文件中。选择“拼音首字母”列的第一行,即C2单元格。在函数框中输入=getpy(B2),这里调用了自定义函数getpy,用于获取B2单元格中汉字...

excel中如何实现提取汉字的拼音首字母?
PY,2)就可以返回指定汉字的拼音首字母:(注意:使用VLOOKUP()函数时,其最后一个参数须用1或True的模糊“默认”查找方式)如下,LOOKUP()的个数可根据汉字的个数决定,由于上面定义的PY最前面有一个""的值,所以可以屏蔽错误,当然也可以用迭代计算的方式获得: =LOOKUP(LEFT(A2),PY)&LOOKUP(...

在excel中如何提取汉字的第一个拼音字母
如A列是汉字,从A1开始,则B1中的公式为:=LOOKUP(CODE(A1),45217+{0,36,544,1101,1609,1793,2080,2560,2902,3845,4107,4679,5154,5397,5405,5689,6170,6229,7001,7481,7763,8472,9264},{"A","B","C","D","E","F","G","H","J","K","L","M","N","O","P","Q","...

Excel 请问如何提取中文拼音第一个字母
假设A列为汉字,提取的拼音第一个字母放在B列,以Excel2010版为例,操作如下:1、单击菜单栏的“开发工具”,”Visual Basic“编辑器,Visual Basic编辑器 2、执行“插入→模块”命令,在模块代码编辑区输入下列代码:Function pinyin(p As String) As String i = Asc(p)Select Case i Case -20319...

请教在EXCEL中把人名的拼音首字母提取的方法
1、利用在线汉字转拼音应用将需要转换的汉字生成拼音;2、将生成的拼音粘贴回excel,利用分列功能分成3列,每列都选文本格式;3、按第三列(该列两字人名为空)排序,将空格排到下方;4、在其后第一列第一行、第二行手动输入第一个、第二个人名首字母,选中两单元格,右键拖动拖动手柄至最下,松开...

相似回答