欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

pythonxlrd与openpyxl使用

时间:2023-05-25

使用python库读取写入

import openpyxlimport xlrd# 用openpyxl创建工作本用于写入wb = openpyxl.Workbook()ws = wb.create_sheet()ws.title = 'demo01'# 利用xlrd读取数据da = xlrd.open_workbook_xls('2022001.xls')table = da.sheets()[0]print(table.nrows) # 行数print(table.ncols) # 列数print(table.row_values(0)) # 获取整行数值# print(table.col_values(1)) # 获取整列数值alldata = []tempdata = []tempdata.append(table.row_values(0))alldata.append(table.row_values(0))for i in range(table.nrows): if table.row_values(i)[5].find('漳州') == 0: if table.row_values(i)[19].find('不限') !=-1: alldata.append(table.row_values(i)) # print(table.row_values(i))for i in range(len(alldata)): if alldata[i][15].find('不限') == 0: pass else: continue if alldata[i][16].find('本科') != -1: pass elif alldata[i][16].find('大专') != -1: pass else: continue tempdata.append(alldata[i]) # if alldata[i][21].find('计算机') == -1: # if alldata[i][21].find('理学') == -1: # if alldata[i][21].find('不限') == -1: # continue # else: # tempdata.append(alldata[i]) # else: # tempdata.append(alldata[i]) # else: # tempdata.append(alldata[i])# 开始写入st = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA']for i in range(len(tempdata)): for j in range(len(tempdata[i])): ny = st[j] nx = i+1 op = ny+str(nx) ws[op]=tempdata[i][j]wb.save('test.xlsx')

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。