import xlrd, xlsxwriter
allxls = [“C:\Users\zhudong\Desktop\azkaban自动爬取\2018-09-01.xlsx”,
“C:\Users\zhudong\Desktop\azkaban自动爬取\2018-09-02.xlsx”,
“C:\Users\zhudong\Desktop\azkaban自动爬取\2018-09-03.xlsx”]
end_xls = “C:\Users\zhudong\Desktop\azkaban自动爬取\99-99-99.xlsx”
def open_xls(file):
try:
fh = xlrd.open_workbook(file)
return fh
except Exception as e:
print(“打开文件错误:” + e)
def get_file_value(filename, sheetnum):
rvalue = []
fh = open_xls(filename)
sheet = fh.sheets()[sheetnum]
row_num = sheet.nrows
for rownum in range(0, row_num):
rvalue.append(sheet.row_values(rownum))
return rvalue
endxls = xlsxwriter.Workbook(end_xls)
for item in allxls:
first_file_fh = open_xls(item)
first_file_sheet = first_file_fh.sheets()
end_xls_sheet = endxls.add_worksheet(first_file_sheet[0].name)
sheet_values = get_file_value(item,0)
for row_index,u in enumerate(sheet_values, start=0):
for i in range(0,len(u)):
end_xls_sheet.write(row_index, i, u[i])
endxls.close()