import os import xlwings as xw app = xw.App(visible = False, add_book = False) file_path = 'C:\\Users\\Administrator\\Desktop\\测试\\来源' file_list = os.listdir(file_path) # workbooks = xw.Book("C:\\Users\\Administrator\\Desktop\\测试统计表") for i in file_list: com = (file_path + '\\'+ i) print(com) workbook = app.books.open(file_path + "\\"+ i) worksheet = workbook.sheets[0] # value = worksheet.range('A1').expand('table') start_cell = (13, 1) end_cell = (16,6) cell_area = worksheet.range(start_cell, end_cell).value print(cell_area) print("="*100) # start_cell = (1, 0) # end_cell = (value.shape[0], value.shape[1]) # cell_area = worksheet.range(start_cell, end_cell).value new_path = 'C:\\Users\\Administrator\\Desktop\\测试' new_list = os.listdir(new_path) print(new_list) for ii in new_list: if os.path.splitext(ii)[1] == '.xlsx': print(os.path.splitext(ii)[1]) try: print(new_path + '\\' + ii) workbooks = xw.Book(new_path + '\\' + ii) sheet = workbooks.sheets[0] scope = sheet.range('A1').expand() print(f'scope is {scope}') sheet.range(scope.shape[0] + 1, 1).value = cell_area workbooks.save() finally: workbooks.close() workbook.close() app.quit()
把测试统计表里的所有工作利润簿指定数据复制到测试下面的报所有表(测试目录只有一个表)
最新推荐文章于 2023-06-12 21:00:33 发布