Openpyxl-如何将单元格值从一个工作簿移动到特定行中的另一个工作簿

时间:2019-07-26 20:08:06

标签: python excel openpyxl

我有两个工作簿,一个主日志和一个表单。我正在尝试从表单中提取单元格值并将其写入主日志,但要在与表单中的数字匹配的特定行中。

我的最终目标是使代码遍历放置在目录中的表单列表。这就是os.walk()函数的作用。

'cells_to_receive'和'complaint_number_master_log'列表中的'$'字符只是占位符,直到我弄清楚动态填充它们的逻辑。

我为代码不完整表示歉意,这是我的第一个编程项目,我正在努力。如果有任何资源或教程,您可以推荐它。

path = 'C:\Users\cmcrae\Desktop\Complaint Python Script\Master Log 
Directory\Master Log.xlsx'
master_log = load_workbook(path)

basepath = 'C:\Users\cmcrae\Desktop\Complaint Python Script\Case Intake 
Directory'
case_intake_list = os.listdir(basepath)

def report_creation():
    dt = str(datetime.date.today())
    report = open('C\Users\cmcrae\Desktop\Complaint Python Script\Daily 
    Execution Reports', 'w')
    report.rename('Report ' + dt + '.txt')

def case_intake_extraction():
    for files in os.walk(case_intake_list):
        if len(case_intake_list) == 0:
            report.open()
            report.write('The case intake directory is empty')
            report.close()
        else:
            complaint_number_check = ['B1']
            complaint_number_master_log = ['A$']
            cells_to_move = ['B2','B3','B4']
            cells_to_receive = ['B$','C$','D$']

            files.load_workbook()
                for row in master_log:
                    for cell in row:
                        if files.complaint_number_check[0].cell.value == 
                        master_log.complaint_number_receive.row
# Check to see if complaint number in cell B1 of the form is within 
# column A of the master log.  If yes, all of the cells_to_move 
# should write to cells_to_receive at the row found in the master log.

0 个答案:

没有答案