# -*- coding: UTF-8 -*-
import os
import xlrd
import xlwt
import xlwings as xw
root_dir = os.path.abspath('.')
write_excel_path = root_dir + "\\demo.csv"
path = root_dir + "\\test"
write_excel_book = xw.Book()
sht = write_excel_book.sheets('sheet1')
#封装文件名称
L = []
for root, dirs,files in os.walk(path):
for file in files:
if os.path.splitext(file)[1] == '.xlsx': #查询文件后缀
L.append(os.path.join(root,file))
print(len(L))
#封装excel数据
sheet_col = []
for i in range(len(L)):
read_excel_path = L[i]
#打开文件,获取excel文件的workbook对象
read_excel = xlrd.open_workbook(read_excel_path,encoding_override="UTF-8")
sheet = read_excel.sheet_by_index(0)
for i in range(sheet.nrows):#循环打印每一行
if i==0:
continue
else:
sheet_col.append(sheet.row_values(i))
for each_col in range(len(sheet_col)):
col = "A" + str(each_col + 1)
sht.range(col).value = sheet_col[each_col]
write_excel_book.save(write_excel_path)
来源:CSDN
作者:qq_42572415
链接:https://blog.csdn.net/qq_42572415/article/details/104259946