What causes “UserWarning: Discarded range with reserved name” - openpyxl

后端 未结 3 1675
[愿得一人]
[愿得一人] 2021-02-12 23:26

I have a simple EXCEL-sheet with names of cities in column A and I want to extract them and put them in a list:

def getCityfromEXCEL():
    wb = load_workbook(fi         


        
相关标签:
3条回答
  • 2021-02-12 23:30

    It's supposed to be a friendly warning letting you know that some of the defined names are being lost when reading the file. Warnings in Python are not exceptions but informational notices.

    Support for defined names is essentially limited to references to cell ranges in openpyxl at the moment. But they can refer to lots of other things like printing settings. However, if the objects/values they refer to are not preserved by openpyxl and the file is saved and later opened by Excel it might complain about the missing objects.

    0 讨论(0)
  • 2021-02-12 23:41

    If you want to ignore it:

    import warnings
    warnings.simplefilter("ignore")
    wb = load_workbook(path)
    warnings.simplefilter("default")
    
    0 讨论(0)
  • 2021-02-12 23:50

    In my case this warning shows up when filtering is on one of my worksheets. I wanted to suppress the warning so that it didn't bother my users and I just put this line in my code before the openpyxl.load_workbook call:

    warnings.simplefilter("ignore")
    
    0 讨论(0)
提交回复
热议问题