`
阅: 2164 | 回: 0
发表于2015/10/24 16:24:23 楼主 
头像 等级:初学者
积分:0
财富值:0.0
身份:普通用户

用公式将汉字转换为拼音的第一个字母

 有时需要在Excel中将大量姓名或名称转换为拼音首字母的简写形式,例如将周伯通转换为“ZBT”。用定义名称和公式的方法可以轻松实现转换,在Windows XP中,以Excel 2003为例方法如下:

    1.定义名称:

    单击菜单插入→名称→定义,在弹出的对话框中在当前工作簿中的名称下的文本框中输入一个名称,如“py”,在引用位置下输入下列代码后确定:

    ={"","吖","","","","","","","","","","","","",

"噢","","","","","","","","","";"","A","B","C","D","E",

"F","G","H","J","K","L","M","N","O","P","Q","R","S","T","W","X","Y","Z"}

 2.假如名单在A2:A100区域中,在B2单元格中输入公式:

    =LOOKUP(LEFT(A2,1),py)&LOOKUP(MID(A2,2,1),py)&LOOKUP(MID(A2,3,1),py)&LOOKUP(MID(A2,4,1),py)

    然后拖动填充柄向下填充公式即可。

 说明:

    1.定义的名称为一个数组,以分号为界分为两行,第一行为汉字,第二行为与第一行汉字对应的拼音第一个大写字母。如果是Windows 7Vista,则需要将定义的名称改为:

    ={"","吖","","","","","","","","","","","","",

"噢","","","","","","","","","";"","A","B","C","D","E",

"F","G","H","J","K","L","M","N","O","P","Q","R","S","T","W","X","Y","Z"}

    2.公式用LOOKUP函数将每个汉字转换成拼音的第一个大写字母。其原理是:Excel中汉字(文本)之间也可以进行比较;汉字在Excel中的排列顺序与拼音顺序相同,排在前面的小于排在其后的。上述定义名称的数组中,每个汉字都是所有拼音首字母相同的汉字中的第一个,例如Excel中排在其他所有拼音首字母为“B”的前面,因而其最小。因此,LOOKUP函数在查找某个不在数组中的汉字,如字时,会在数组的第一行中查找小于它的最大值,然后返回最后一行同列的值“B”

    另外,由于在Windows XPWindows 7VistaExcel对汉字的排列顺序有所不同,故定义的名称内容也不同。如果在Windows 7Vista中使用XP中定义的数组,LOOKUP函数第二个参数中的值未按升序排列,可能无法返回正确的结果。

    3.对于多音字只能返回一种结果。

    4.如果有多于四个的汉字,继续在公式后面添加即可。如有第五个汉字,则加上“&LOOKUP(MID(A2,5,1),py)”

我的个性签名

快速回复

目前不允许游客发表,请 登录 注册 后再发贴。