昨天接到人事小姐姐求助減輕複製粘貼的重複工做量,分享一下代碼 半路新手上路 耶python
把 2.xlsx 表裏的第二列 的數據複製粘貼到 test.xlsx的第一列spa
python3.6.2excel
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')
ps:python真是個好東西,太方便了!code