在Excel里面怎么自动提取字段的第一个汉字的拼音首字母

在Excel里面怎么自动提取字段的第一个汉字的拼音首字母,第1张

函数或者vba(也可以装个插件工具箱)

函数的话,可以试试这两个

MID("ABCDEFGHJKLMNOPQRSTWXYZ",MATCH(LEFT(A1),{"啊","芭","擦","搭","蛾","发","噶","骸","击","喀","垃","妈","拿","哦","啪","期","然","撒","塌","挖","昔","压","匝"}),1)

或者

LOOKUP(LEFT(A1),{"吖","A";"八","B";"嚓","C";"咑","D";"妸","E";"发","F";"猤","G";"铪","H";"丌","J";"咔","K";"垃","L";"呒","M";"拏","N";"噢","O";"妑","P";"七","Q";"亽","R";"仨","S";"他","T";"屲","W";"夕","X";"丫","Y";"帀","Z"})

步骤:

第一步、启动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)。

定义一个SplitStr函数,参数是文本框中的字符串,使用ByteType函数返回这个字符串中每个字符所占的字节数,如果返回mbSingleByte(单字节),那么说明这个字符是字母或数字,如果是双字节,那么说明这个字符是汉字。根据字符的字节数通过copy函数获取当前这个字符,然后调用GetSpell函数来返回这个字符的拼音简码。主要代码如下:function TForm1SplitStr(str: string): string;vartext: String;i, Count: Integer;begintext := '';i := 1;while i <= Length(str) dobeginif ByteType(str, i) = mbSingleByte thenCount := 1elseCount := 2;

以上就是关于在Excel里面怎么自动提取字段的第一个汉字的拼音首字母全部的内容,包括:在Excel里面怎么自动提取字段的第一个汉字的拼音首字母、excel中如何实现提取汉字的拼音首字母、Delphi中如何获取汉字拼音简码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9515860.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存