基本信息
源码名称:excel合并
源码大小:1.30KB
文件格式:.py
开发语言:Python
更新时间:2021-09-02
   源码介绍
:文件夹下excel表格合并到一张excel。

for dir_path, subpaths, files in os.walk(path):
    for file in files:
        file_path = os.path.join(dir_path, file)
        b=xlrd.open_workbook(file_path)
        count=len(b.sheets())
        for sheet in b.sheets():
            nrows=sheet.nrows
            ncols=sheet.ncols
            for i in range(nrows):
                for j in range(ncols):
                    if (sheet.cell(i,j).ctype==3):
                        date_value=xlrd.xldate_as_tuple(sheet.cell_value(i,j),b.datemode)
                        cell_value=str(date_value[0]) '/' str(date_value[1]) '/' str(date_value[2])
                    else:
                        cell_value=sheet.cell_value(i,j)
                    worksheet.write(a i,j,cell_value)
            a=a nrows
            f.write('已读取:' file_path ',' '工作表' sheet.name ',' '行数:' str(nrows) ',' '已累计汇总:' str(a) '\n')
            print('已读取:' file_path ',' '工作表' sheet.name ',' '行数:' str(nrows) ',' '已累计汇总:' str(a))
f.close()
workbook.close()