导致“用户警告:使用保留名称丢弃范围"的原因是什么? -openpyxl [英] What causes "UserWarning: Discarded range with reserved name" - openpyxl

查看:157
本文介绍了导致“用户警告:使用保留名称丢弃范围"的原因是什么? -openpyxl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的EXCEL工作表,其中A列中有城市名称,我想提取它们并将它们放在列表中:

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(filename='test.xlsx', read_only=True)
    ws = wb['Sheet1']
    cityList = []

    for i in range(2, ws.get_highest_row()+1):
        acell = "A"+str(i)
        cityString = ws[acell].value
        city = ftfy.fix_text_encoding(cityString)            
        cityList.append(city)

getCityfromEXCEL()

带有一个运行良好的小文件(70行).现在我正在处理一个大文件(8300行),它给了我这个错误:

With a small file that worked perfectly (70 rows). Now I'm processing a big file (8300 rows) and it gives me this error:

/Library/Python/2.7/site-packages/openpyxl/workbook/names/named_range.py:121: UserWarning: Discarded range with reserved name
  warnings.warn("Discarded range with reserved name")

但它不会中止.只是似乎不再继续了.有人可以告诉我什么可能导致错误吗? .xlsx中有东西吗?有什么特别提示可以找我吗?

but it does not abort. It just does not seem to continue anymore. Can someone tell me what might cause the error? Is it something in the .xlsx? Any special hints what I can look for?

推荐答案

应该是一个友好的警告,让您知道在读取文件时某些定义的名称正在丢失. Python中的警告不是例外,而是信息性提示.

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.

目前,对已定义名称的支持仅限于对openpyxl中单元格范围的引用.但是他们可以引用许多其他内容,例如打印设置.但是,如果它们引用的对象/值未由openpyxl保留,并且文件被保存并随后由Excel打开,则可能会抱怨缺少对象.

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.

这篇关于导致“用户警告:使用保留名称丢弃范围"的原因是什么? -openpyxl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆