【问题标题】:How to skip cell values that are not in list with openpyxl?如何跳过不在 openpyxl 列表中的单元格值?
【发布时间】:2022-12-07 22:14:08
【问题描述】:

我尝试跳过不在特定列列表中的 excel 值。

所以这是代码:

import openpyxl

excelWorkbook = openpyxl.load_workbook(path, data_only=True)

def controle_punt_160():
    sheet_factuur = excelWorkbook[" Overzicht fruit-groente Noord "]
    list_fruit_groente = ['Appels', 'Ananas', 'Waspeen',
                           'Tomaten Cherry', 'Sinaasapp',
                           'Watermeloen', 'Rettich', 'Appel', 'Peen',
                           'Mandarijnen', 'Wortel', 'Snacktomaat', 'Rettich']

    for row in sheet_factuur.iter_rows():  # type: ignore
        for cell in row:
            if "C" in cell.coordinate:
                if [cell.value in  list_fruit_groente] or cell[0].value is not None :
                    print(cell.value)

但输出仍然是:

None
None
None
Soort fruit/groente
None
Ananas
Waspeen
Appel
None
None
None
Rettich
Sinaasappel
Waspeen
None
None
None
Snacktomaat
Sinaasappel
Appel
None
None
None
Wortel
Sinaasappel
Appel
None

问题:如何跳过所有不在列表中的单元格值?

【问题讨论】:

    标签: python openpyxl


    【解决方案1】:

    您正在检查 cell[0].value 但正在打印 cell.value。

    【讨论】:

    • 你是什​​么意思?因为如果我只是这样做: cell[0].value 也不起作用
    猜你喜欢
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-24
    相关资源
    最近更新 更多