Openpyxl:如何遍历column2,使用这些值检查条件,然后将输出放置在column 5中?

问题描述

有人可以帮我吗? 我想遍历第2列中的int值,使用if,elif语句检查条件,然后将输出替换为同一行的第5列。

我正在使用的工具 皮查姆2020.1.1 Openpyxl 3.0.4

到目前为止,我已经有了这段代码,该代码从源中获取值并将它们放置在新的工作表中

'''

将单元格值从源excel文件复制到目标excel文件

    for i in range(1,max_rows):
        for j in range(1,max_columns):
            # reading cell value from source excel file
            c = sheet.cell(row=i,column=j)

            # writing the read value to destination excel file
            sheet_name.cell(row=i,column=j).value = c.value
            sheet_name.cell(row=i,column=j).font = cell_font

            for total in sheet_name.cell(row=max_rows,column=2):
                for Box in sheet_name.cell(row=max_rows,column=5):
                    if total.value == 1 and total.value <= 6:
                        Box.value = 1
                    elif total.value == 7 and total.value <= 10:
                        Box.value = 2
                    elif total.value > 10:
                        Box.value = 3
                    else:
                        Box.value = 0

'''

错误是 make_packing_list中的文件“ D:/kaiawhiproject/app.py”,第233行 对于sheet_name.cell(row = max_rows,column = 2)中的总数: TypeError:“ Cell”对象不可迭代

我是Openpyxl,Python和Stackoverflow的新手。因此,任何建议将不胜感激。谢谢

[屏幕截图] [1] [1]:https://i.stack.imgur.com/9dAKh.png

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)