excel.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:rowgenerators 作者: Metatab 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号