赞
踩
- import xlwings as xw
- import os
-
-
- filename=r"E:\DZX\OFFICE\劳务费申述\加盟群\信阳泉云2月份劳务费申诉.xlsx" #读取文件
- filename1=r"E:\DZX\OFFICE\劳务费申述\劳务费申诉汇总.xlsx" #读取文件名称
-
-
-
- def merger_workbook(filename,filename1): #,wb1
- # wb = xw.Book(filename) #打开文件
- wb = app.books.open(filename)
- sheets_count = wb.sheets.count
- print(sheets_count)
- for j in range(0,sheets_count):
- print(j)
- detail_sheet = wb.sheets[j] # ("sheet名字") #sheet名字
- print(detail_sheet)
- last_row_index=detail_sheet.range('A2').expand('table').last_cell.row #这表格最后一列
- print(last_row_index)
- rg = "A2:XFD" + str(last_row_index) #范围
- # print(rg)
- # with open(r'E:/DZX/text/linkS.txt','a',encoding='utf8') as f:
- # f.write(f"\n{detail_sheet}\n{last_row_index}\n{rg}")
- work_detail = detail_sheet.range(rg).value #选中范围的值
- # print(work_detail)
-
- #上面是需要复制的,复制到下面这里面来
- # wb1=xw.Book(filename1) #打开文件
- # wb1 = app.books.open(filename1)
- detail_sheet1= wb1.sheets[0] #sheet名称
- last_row_index1=detail_sheet1.range('A2').expand('table').last_cell.row #这表格最后一列
- last_row_index1=last_row_index1+1
- detail_sheet1.range('A'+str(last_row_index1)).expand('table').value = work_detail
- wb1.save(filename1) #保存地址加文件名称
- # wb1.close()
- wb.close()
-
-
-
-
-
-
-
-
-
-
- if __name__ == '__main__':
- app = xw.App(visible=False,add_book=False)
- # merger_workbook(filename,filename1)
- cont = os.listdir(r"E:\DZX\OFFICE\劳务费申述\加盟群")
- # print(cont)
- # wb1=xw.Book(filename1) #打开文件
- wb1 = app.books.open(filename1)
- for i in range(0,len(cont)):
- root = r"E:\DZX\OFFICE\劳务费申述\加盟群"
- filename = os.path.join(root,cont[i])
- # wb1 = app.books.open(filename)
- merger_workbook(filename,filename1)#,wb1
- wb1.save(filename1)
- wb1.close()
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。