python操作excel表格根据sheet,并且把这列每项内容转换成大写首字母

# -*- coding:utf-8 -*-
import openpyxl
import pypinyin


wb = openpyxl.load_workbook(r"D:\PythonCode\AfterInstalled\爬取共享平台\人口库设计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)

 

上一篇:vba 新建并保存工作簿


下一篇:XLSX做导入功能时,处理日期类型数据