excel中汉字转成声母

碰到这个业务,就是需要将数据库每个客户的名字转成声母放在excel中,看了下网上,一般都用到了gb2312sm.lib文件,实则自己也可写一个函数,然后封装在库里也可.

 

Private   Function GetPY(ByVal strParmeter As StringAs String
          
Dim intTmp     As String, i       As Long
            
          
For i = 1 To Len(strParmeter)
                  intTmp 
= Asc(Mid(strParmeter, i, 1))
    
                  
If intTmp < Asc(""Then
                          GetPY 
= GetPY & "*"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "A"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "B"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "C"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "D"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "E"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "F"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "G"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "H"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "J"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "K"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "L"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "M"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "N"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "O"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "P"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "Q"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "R"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "S"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "T"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "W"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "X"
                  
ElseIf intTmp >= Asc(""And intTmp < Asc(""Then
                          GetPY 
= GetPY & "Y"
                  
ElseIf intTmp >= Asc(""And intTmp < 0 Then
                          GetPY 
= GetPY & "Z"
                  
ElseIf (intTmp >= 65 And intTmp <= 91Or (intTmp >= 97 And intTmp <= 123Then
                          GetPY 
= GetPY & Mid(strParmeter, i, 1)
                  
Else
                          GetPY 
= GetPY & "*"
                  
End If
          
Next
  
End Function


 先用VBA写个宏函数,然后在单元格中调用,然后利用自动填充柄填充功能来实现余下的.

比如:对B1就可以直接在单元格中写=GetPy(A1),然后双击填充柄即可.然后再导入到数据库中去.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值