想用做一个 Excel 表格合并时遇到的一些问题

刚学python没多久,想做一个表格一键合并的程序,发现是倒数第二行的#data有问题,导致数据不能全部得导入新文件,望指正一下错误

代码如下
————————————
import xlrd
import xlwt
import os

title = ['考勤号码', '姓名', '部门', '日期', '时间']
workbook = xlwt.Workbook('utf-8')
sheet=workbook.add_sheet('file_1',cell_overwrite_ok=True)
path = 'C:/Users/Administrator/Desktop/打卡记录/'
path = 'C:/Users/Administrator/Desktop/path/'
file_list = os.listdir(path)

print(file_list)

for file in file_list:
file_name = os.path.join(path,file)

print(file_name)

workbook = xlrd.open_workbook(file_name)
sheet_name = workbook.sheet_names()  
#print(workbook)
j = 0
for i in title:
    sheet.write(0,j,i)
    j += 1

*for file1 in sheetname:
data = []
table = workbook.sheetbyindex(0)
rows = table.nrows
cols = table.ncols
for k in (range(rows)[1:]):
data.append(table.rowvalues(k))
for h in range(len(data)):
for k in range(len(data[h])):
sheet.write(h+1,k,data[h][k])

print(data)*

f.save('result.xlsx')

讨论数量: 1
Summer
3个月前 评论
Kerier (楼主) 3个月前

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!