使用openpyxl根据条件将列从一个工作簿复制到另一个工作簿

时间:2020-04-15 01:31:24

标签: python excel openpyxl

我目前正在使用openpyxl软件包。 我的Excel文件中有两张纸 工作表0是签发表 工作表1是夏季帐单

我需要根据当前月份值填写信息,该信息可在结算单的F1单元格中找到。 我需要在签到表中找到当前月份并为该列填充值

下面是我到目前为止尝试过的代码,我从帐单中获取价值,也能够在签发单中找到价值,但在填写签发单中的列时未获得成功。

下面是我到目前为止开发的代码

from openpyxl import load_workbook
import openpyxl
from ConfigDetails import ConfigDetails
import traceback
import sys


class SignOff:
    def __init__(self,billingSummary):
        self.outputFile= billingSummary
        self.indivSheet=0
#        print(":::",self.gwlFileName)
        self.summaryRow=0
        ConfigDetails.logger.info("************Signoff And Wire-Transfer Request Process start***************")
        ConfigDetails.logger.info("Output File::{}".format(self.outputFile))

    def updateSignOff(self):
        ConfigDetails.logger.info("process Signoff Start ")  
        try:
            workbook = load_workbook(filename=self.outputFile)
            workbook.active = 1    
            sheet = workbook.active
#findng month             
            Month = sheet ['F1']
            print(Month.value)


            for value in sheet.iter_rows(min_row=5,max_row=13,min_col=13,max_col=13,values_only=True):
                print(value)
                BillingValue[i]=value


#            print (BillingValues)

            workbook.active = 0 
            sheet = workbook.active
            SignOffMonth = sheet ['D3']
#            print(SignOffMonth.value)
#finding Column in signoffsheet from using Month Variable             
            for col in sheet.iter_cols():
                for cell in col:
                    if cell.value == Month.value:
#                        col.value = BillingValues
                        print (cell.value)


#            summryRow = 'J'+str(self.summaryRow)
#           sheet[summryRow]=0
            workbook.save(filename=self.outputFile)
            ConfigDetails.logger.info(" Process Signoff completed") 


        except Exception:
            print("Error in Trad Parser Processing - Signoff Sheet Error",Exception)
            traceback.print_exc(file=sys.stdout)
            sys.exit()    

I need to fill in this column in signoffsheet

0 个答案:

没有答案