【发布时间】:2017-06-04 02:36:28
【问题描述】:
我正在尝试阅读 xlsx do 文档,查找特定车道并打印一个区域,但不打印无车道。当“无”在特定列中时也打破循环。
def some():
for r in range(1, ws.max_row):
for c in range(1, ws.max_column):
db = ws.cell(row=r, column=c)
if db.value == 'this one':
for rows in ws.iter_rows(min_row=r + 1, min_col=c - 1,
max_row=r + 30, max_col=c):
for cell in rows:
if cell.value is None:
if column_index_from_string(db.column) == c:
return
else:
print(cell.value, end=" ")
print()
此代码返回唯一的 1 个通道,然后中断头部循环。
输出:
1315 文本。
文件格式:https://drive.google.com/file/d/0B_bbUxPgcVESVGstWWRxV3k4emM/view。我无法解决这个问题。请原谅本机错误。我是新蟒蛇,正在寻找答案。
【问题讨论】:
-
您能否通过 google drive/dropbox 包含您的 excel 文件并提及您要提取的行?
-
@UrielEli 如果这真的是这里要问的问题,因为他说“当 None 在特定列中时也打破循环。”那为什么我的回答没有被接受?目前它被否决为-1,当我认为它回答了我刚刚引用的问题时。
-
@Cephlin 我不知道你为什么被否决了,但这里的标准是不回答此类重复但关闭它们,因此人们将被重定向到完整的对话线程。
-
@UrielEli 好吧,这很公平,但也许他们本可以留下评论通知我这一点,而不是公然否决正确答案... 否决正确答案似乎很奇怪。谢谢你告诉我。