from xpinyin import Pinyin
import xlrd
import xlsxwriter
data = xlrd.open_workbook('laji.xls')
print(data.sheet_names()) # 输出所有页的名称
table = data.sheets()[0] # 获取第一页
nrows = table.nrows # 为行数,整形
workbook = xlsxwriter.Workbook('laji_new.xlsx')
worksheet1 = workbook.add_worksheet()
# 遍历输出所有行值
for i in range(nrows):
data=table.row_values(i)
name=data[0]
lei=data[1]
pin=Pinyin()
name_pin=pin.get_pinyin(name)
if lei==1.0:
lei_pin="ke"
elif lei==2.0:
lei_pin="you"
elif lei==4.0:
lei_pin="chu"
elif lei==8.0:
lei_pin="qi"
else:
lei_pin="da"
print(name,name_pin,lei_pin)
worksheet1.write(i, 0, name)
worksheet1.write(i, 1, name_pin)
worksheet1.write(i, 2, lei)
worksheet1.write(i, 3, lei_pin)
workbook.close()
【Python批量处理表格】汉字转拼音
最新推荐文章于 2024-03-30 21:20:48 发布