把测试统计表里的所有工作利润簿指定数据复制到测试下面的报所有表(测试目录只有一个表)

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()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值