用python自动复制excel的sheet表数据到新表
例如: 2.xlsx 表里的第二列 的数据复制粘贴到 test.xlsx的第一列
步骤如下:
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')