# -*- coding:utf-8 -*- import openpyxl import pypinyin wb = openpyxl.load_workbook(r"D:PythonCodeAfterInstalled爬取共享平台人口库设计20200419.xlsx") ws = wb.get_sheet_by_name('人口基准信息') data_dict = {"nodes": [], "links": []} for i in range(2, 50000): # 获取很多行,中间程序有中断 # xuqiu_bumen = ws.cell(row=i, column=3).value mulu = ws.cell(row=i, column=4).value # print(mulu) # print(mulu) if mulu == None: break a = pypinyin.pinyin(mulu, style=pypinyin.FIRST_LETTER) b = [] for i in range(len(a)): b.append(str(a[i][0]).upper()) c = ''.join(b) print(c)