昨天接到人事小姐姐求助减轻复制粘贴的重复工作量,分享一下代码 半路新手上路 耶
把 2.xlsx 表里的第二列 的数据复制粘贴到 test.xlsx的第一列
python3.6.2
from openpyxl import Workbook from openpyxl import load_workbook from openpyxl.writer.excel import ExcelWriter wb = load_workbook (‘C:\\Users\\elan\\Desktop\\python\\2.xlsx‘) ws = wb[‘Sheet1‘] sheet = wb.active a = sheet.max_row b=[] i=0 while i < a: i = i+1 print(ws.cell (i,2).value) b.insert(i, ws.cell (i,2).value) wbtest = load_workbook (‘C:\\Users\\elan\\Desktop\\python\\test.xlsx‘) ws = wbtest[‘Sheet1‘] sheet = wb.active i = 0 while i < a: ws.cell (i+1,1).value = b[i] i = i+1 wbtest.save (‘C:\\Users\\elan\\Desktop\\python\\test.xlsx‘)
原文地址:https://www.cnblogs.com/Elanlalala/p/10538730.html
时间: 2024-10-07 20:50:36