# -*- coding: utf-8 -*-
import xlrd, xlwt
def read():
data = xlrd.open_workbook("D:\\pyproject\\python_excel\\1.xlsx") #打開已存在的excel
# data.sheets()
tables = data.sheet_names() #获取sheet表名字
for table in tables:
data1 = xlwt.Workbook()
sheet1 = data1.add_sheet('汇总', cell_overwrite_ok=True) #写入excel
sheet = data.sheet_by_name(table)
print(table)
a = sheet.col_values(1, 1) #读取对应列的数据
b = sheet.col_values(4, 1)
c = sheet.col_values(7, 1)
print(a, b, c)
for i in range(0, len(a)):
sheet1.write(i, 0, a[i]) #在excel中写入对应位置
sheet1.write(i, 1, b[i])
sheet1.write(i, 2, c[i])
data1.save('D:\\pyproject\\python_excel\\2.xls')
if __name__ == '__main__':
read()