首页 > 解决方案 > 使用python进行特殊粘贴

问题描述

我们需要从具有一些复杂格式的现有 excel 文件中进行特殊粘贴。此外,使用基于 win32 的应用程序(如 :openpyxl 或 xlwings)存在许可证限制。是否有任何替代库可以在 python 中做同样的事情?

我们尝试使用以下代码:

代码 :

wb = openpyxl.load_workbook(file_location,data_only=True)
    wb.save(file_location1)
    
    sourceFile=wb
    targetFile= openpyxl.load_workbook(file_location1)
    sourceSheetNames=['Overview']
    for sheet in sourceSheetNames:
        sourceFileActiveSheet = sourceFile[sheet]
        targetFileActiveSheet = targetFile[sheet]
        maxRowsourceFile = sourceFileActiveSheet.max_row
        ##for rowNum in range(1, maxRowsourceFile + 1):
        for rowNum in range(4, 30):
                for colNum in range(1, 30): # copy everything up to and including column 30
                    value = sourceFileActiveSheet.cell(row=rowNum, column=colNum).value
                    print(value)
                    targetFileActiveSheet.cell(row=rowNum, column=colNum).value= value
    targetFile.save(file_location1)

附件中添加的excel文件快照

在此处输入图像描述

标签: pythonvbaopenpyxl

解决方案


推荐阅读