首页 > 其他分享 >EXCEL获取拼音首字母

EXCEL获取拼音首字母

时间:2023-08-02 09:45:00浏览次数:25  
标签:tmp 拼音 EXCEL char 首字母 模块

Excel 2016
按组合键ALT+F11调出VB窗口——插入——模块(复制代码到新模块中,复制完后始可关闭VB窗口)

复制以下代码到模块中
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 >= 53679 And tmp <= 54480) Then

    getpychar = "Y"

    ElseIf (tmp >= 54481 And tmp <= 62289) Then

    getpychar = "Z"

    Else '如果不是中文,则不处理

    getpychar = char

    End If

End Function

'逐个取ASC码

Function getpy(str)

    For i = 1 To Len(str)

        getpy = getpy & getpychar(Mid(str, i, 1))

    Next i

End Function

回到Excel里面,使用函数=getpy(...),读取拼音首字母

标签:tmp,拼音,EXCEL,char,首字母,模块
From: https://www.cnblogs.com/kewenpu/p/17599739.html

相关文章

  • easyExcel设置自动换行
    1//内容样式策略2WriteCellStylecontentWriteCellStyle=newWriteCellStyle();3//垂直居中,水平居中4contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);5contentWriteCellStyle.setHorizontalAlignment(......
  • Java实现读取Excel文件并逐行写入到新的Excel文件中
    在日常开发中,经常需要处理Excel文件,其中一种常见的需求是将原始Excel文件的内容逐行写入到新的Excel文件中或者写入数据中。本篇博客将介绍使用Java编程语言以及ApachePOI库来实现这一功能。ApachePOI是一个开源的Java库,用于处理MicrosoftOffice格式的文件,包括Excel。1.环境......
  • Java导入、导出excel
    Excel是由四个元素组成的分别是:WorkBook(工作簿)、Sheet(工作表)、Row(行)、Cell(单元格),其中包含关系是从左至右,一个WorkBook可以包含多个Sheet,一个Sheet又是由多个Row组成,一个Row是由多个Cell组成。1.1创建Excel的元素1)创建WokrBookWorkbook workbook = new XSSFWorkboo......
  • python怎么把json文件夹转成Excel表?
    1、python怎么把json文件夹转成Excel表?2、Python代码json数据再别的目录下怎么调用?3、【Python】浅谈python中的json4、python的json怎么用5、如何使用Python处理JSON数据python怎么把json文件夹转成Excel表?可以用pandas来读取json文件,再to_excel保存为Excel文件。可......
  • 如何在Excel中实现表关联取值
    需求: 员工表:编号,姓名工资表:编号,工资现要在Excel中在工资表后加一列把员工表中的姓名取过来。解决: 可以通过Vlookup实现,在新的列中添加函数  =VLOOKUP(@D:D,A2:B5,2,FALSE)参数一:关联列(即工资表的编号字段)(选中编号列即可)参数二:查询区域(选中查询区域,及员工表数据区域,......
  • Excel VBA 窗体UserForm制作菜单栏与添加窗体最大化最小化功能(转载)
    窗体'--------------------------------------------------------'->Forms'Module'ClassModules'--------------------------------------------------------OptionExplicitPrivateDeclareFunctionFindWindowLib"user32&qu......
  • 9.EXCEL数量统计方法
    COUNTIFS函数是COUNTIF函数的拓展,常用于对符合多个条件的单元格进行个数统计。它的函数语法为: =COUNTIFS(条件区域1,条件1,条件区域2,条件2,…)如果要说countifs函数和countif区别,那就是前者可以有多个条件判断,countif是单一条件判断,countif(条件区域1,条件1) COUNTIF实际案......
  • pandas模块--------------------------------相同(不同)文件夹下相同格式的Excel表格数
    上代码:importpandasaspdimportos#文件路径file_dir=r'C:/Users/Administrator/Desktop/test/'#构建新的表格名称new_filename=file_dir+'/new_file.xlsx'#找到文件路径下的所有表格名称,返回列表file_list=os.listdir(file_dir)new_list=[]forfileinfile_list:......
  • python openqyxl 操作excel
    importosimportsysfromopenpyxlimportload_workbookclassExcel:#读取数据def__init__(self,excel_path,sheet_name):""":paramexcel_path:excel文件路径:xx/xxx.xlsx:paramsheet_name:需要打开表格名字:sheet1......
  • python 比较两个excel A有b没有
    importpandasaspd#读取第一个Excel文件df1=pd.read_excel('excel_file1.xlsx')#读取第二个Excel文件df2=pd.read_excel('excel_file2.xlsx')#找出在df1中存在但不在df2中的行missing_rows=df1[~df1['列名'].isin(df2['列名'])]#保存缺失的数据到新的E......