python xlrd与openpyxl使用

使用python库读取写入

import openpyxl
import 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')

你可能感兴趣的:(python,开发语言,后端)