data.xlsx那张表格好像有问题
Closed this issue · 3 comments
taotaobao666 commented
我跑了一下你的原码,发现出现4149行那里
if len(row) != 0:
equip_index_to_row_index[index] = row[0].row有错,说是EmptyCell没有row属性,
然后我看了下row[0]的数据,发现
...
<ReadOnlyCell 'one'.A400>
<class 'openpyxl.cell.read_only.ReadOnlyCell'>
<ReadOnlyCell 'one'.A401>
<class 'openpyxl.cell.read_only.ReadOnlyCell'>
<class 'openpyxl.cell.read_only.EmptyCell'>
...
读取Data.xlsx那里会读取一个空行进来,导致无法运行,老哥能看看怎么改一下?
...我自己比较笨,加了个i变量强制控制只循环到401行然后就好了,
Python玩的不太6,老哥看看能不能从读取那边改下?或者修改下xlsx表格?
我自己试着清空了Data.xlsx后面的东西,但是发现还是会读取一个空行进来,这是不是openpyxl的问题呢?
fzls commented
好的,这个暂时现加个异常保护吧=、=问题不大,不影响逻辑,可能是末尾多了几个空行= =
if len(row) != 0:
try:
equip_index_to_row_index[index] = row[0].row
except Exception as err:
logger.error("load row index failed, err={}".format(err))
lmxyy commented
我加了个判断,也解决了
for row in db_one.rows:
row_value = [cell.value for cell in row]
if len(row_value) == 0:
continue
index = row_value[0]
realname = row_value[1]
name_one[index] = row_value
equip_index_to_realname[index] = realname
if len(row) != 0 and hasattr(row[0], 'row'):
equip_index_to_row_index[index] = row[0].row
fzls commented
0-0