如果条件允许,Python会优于两个

时间:2018-01-08 09:16:03

标签: excel python-3.x

我做了python脚本,它在excel表中更新价格并将其写在第3列:

sample

我是这样做的:

 import os, openpyxl

    os.chdir('C:\\Users\\Tadas\\Documents\\Python_pvz')

    wb = openpyxl.load_workbook('pardavimai_paprasti.xlsx')
    sheet = wb.get_sheet_by_name('Sheet')



    for rowNum in range(6, sheet.max_row):  
        customer = sheet.cell(row=rowNum, column=1).value
        article = sheet.cell(row=rowNum, column=2).value
        if customer == 242061 and article == '0288-0482':
           sheet.cell(row=rowNum, column=3).value = 1
        elif customer == 242061 and article == '0288-0757':
            sheet.cell(row=rowNum, column=3).value = 2 
        elif customer == 242061 and article == '1159-0757':
            sheet.cell(row=rowNum, column=3).value = 3


wb.save('updatedpardavimai.xlsx')        

我怎样才能改进代码,否则我将不得不复制这些elif,直到我发疯为止?

0 个答案:

没有答案