def __iter__(self):
"""Iterate over all of the lines in the file"""
self.start()
wb = open_workbook(filename=self.url.path)
ts = self.url.target_segment
# Without this check, failure to provide a target_segment will cause the return
# of the first worksheet.
#if not ts:
# raise RowGeneratorError("URL does not include target file in fragment: {}".format(self.url))
try:
try:
s = wb.sheets()[int(ts) if self.url.target_segment else 0]
except ValueError: # Segment is the workbook name, not the number
s = wb.sheet_by_name(ts)
except XLRDError as e:
raise RowGeneratorError("Failed to open Excel workbook: '{}' ".format(e))
for i in range(0, s.nrows):
yield self.srow_to_list(i, s)
self.finish()
评论列表
文章目录