列的写入方法没有找到,都是按行写入,有列的读取方法,但是没有按列写入
import os
import xlrd
from openpyxl import load_workbook
path = os.path.join(os.getcwd(), 'test.xlsx')
path01 = os.path.join(os.getcwd(), r"resident_export['20190325231422'].xlsx")
# 因为不知道为什么这个excel用openpyxl打不开
wb = xlrd.open_workbook(path)
wb1 = load_workbook(path01)
sheet = wb.sheet_by_name('个人健康档案')
resident_sheet = wb1["residentList"]
lis = list()
for i in range(35, 40):
cols = sheet.col_values(i, start_rowx=2)
res = ["否" if x != '是' else x for x in cols]
lis.append(res)
print(lis)
# 朝指定列写数据
# rows = ws1.max_row # 最大行数
colums = [49, 50, 51, 53, 54]
y = 0
for col in colums:
for x in range(2, len(lis[y])+2):
resident_sheet.cell(row=x, column=col).value = lis[y][x - 2]
y += 1
wb1.save(path01)