python汉字转拼音&创建Excelpython 时间格式化
List和元组添加元素
创建一个Excel 并往sheet里写入文件
汉字转拼音
惜秦皇汉武,略输文采;唐宗宋祖,稍逊风骚。 一代天骄,成吉思汗,只识弯弓射大雕。 俱往矣,数风流人物,还看今朝 posted @ 2021-10-22 23:30 darling331 阅读(96) 评论(1) 编辑 收藏 举报 EXCEL汉字转拼音 WORD转换法及用VBA宏自建函数发布者: 匿名 2017年11月20日 围观次 点赞:3 将中文姓名直接转为中文拼音,这里有两个方法提供,一个是用WORD来做中转转换,一个是用VBA宏来转换 一、WORD法 二、VBA宏 Function PinYin(TXT As Variant, Delimiter As String, Tpy As Byte, Optional FirU As Boolean = False) As String 'Delimiter,隔离符号; 'Tpy定义返回格式: '1,带用数字表示的声调 '2,无声调 '3,仅首字母 '4,带传统声调 'FirU,各单词首字母是否大写,默认小写 Dim N As Integer Dim ASCID As Long Dim Y As Byte Dim M_Txt As String Dim M_PY As String Dim MI_PY As String On Error Resume Next TXT = Trim(TXT) If TXT = "" Then PinYin = "" Exit Function End If If PY_DB(72, 94) <> "ā/á/ǎ/à" And Tpy = 4 Then Call DealVal_2 ElseIf PY_DB(72, 94) <> "a1" And Tpy < 4 Then Call DealVal_1 End If For i = 1 To Len(Trim(TXT)) M_Txt = Mid(Trim(TXT), i, 1) If M_Txt = "" Then MI_PY = "" Else ASCID = Asc(M_Txt) For N = 1 To UBound(PY_Index) If PY_Index(N) < ASCID Then Exit For Next N PYDB_Index = PY_Index(N - 1) - ASCID If PYDB_Index < 0 Or PYDB_Index > 93 Then M_PY = M_Txt Y = 1 Else M_PY = PY_DB(N - 1, PYDB_Index + 1) End If End If Select Case Tpy Case 1 MI_PY = M_PY Case 2 MI_PY = IIf(M_PY = M_Txt, M_PY, Mid(M_PY, 1, Len(M_PY) - 1)) Case 3 MI_PY = Left(M_PY, 1) Case 4 MI_PY = M_PY End Select PinYin = PinYin & IIf(M_PY = M_Txt, MI_PY, IIf(Y = 1, Delimiter & MI_PY & Delimiter, IIf(i = Len(Trim(TXT)), MI_PY, MI_PY & Delimiter))) Y = IIf(Y = 1, IIf(M_PY = M_Txt, 1, 0), 0) Next i If FirU Then PinYin = Application.WorksheetFunction.Proper(PinYin) End Function 函数的声明:Function PinYin(TXT As Variant, Delimiter As String, Tpy As Byte) As String, 这里第三个参数 Tpy是定义返回格式,主要有以下几种: 1,带用数字表示的声调 2,无声调 3,首字母 4,首字母并大写 5,带传统声调 假设 TXT="my name is: 中国 1." 用 PinYin(TXT," ",5)调用,将得到:my name is: zhōng/zhòng guó 1. 用 PinYin(TXT," ",4,1)调用,将得到:My Name Is: Zhōng/Zhòng Guó 1. 顶(3) 踩(1) EXCEL 转换 vba 宏 汉字 拼音 【搜索相关内容】[打印] [关闭] 上一篇:MAX/MIN+IF数组求取多重条件最大值最小值 下一篇:EXCEL使用VBA SQL读取ACCESS数据库内容 您可能还会对下面的文章感兴趣:相关文章
最新评论 |