Skip to content

Commit

Permalink
Merge 2296e62 into 1d33ca0
Browse files Browse the repository at this point in the history
  • Loading branch information
chrullrich committed Apr 23, 2019
2 parents 1d33ca0 + 2296e62 commit 0d1f1ea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changes
Version X.X
-----------

* Updated :func:`petl.io.xlsx.fromxlsx` for compatibility with
openpyxl 2.6+ (:issue:`465` - :user:`chrullrich`).

* Added support for reading from remote sources with gzip or bz2 compression
(:issue:`463` - :user:`H-Max`).

Expand Down
8 changes: 6 additions & 2 deletions petl/io/xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ def __iter__(self):
if self.range_string is not None:
rows = ws[self.range_string]
else:
rows = ws.iter_rows(row_offset=self.row_offset,
column_offset=self.column_offset)
ws_max_row = ws.max_row or 0
ws_max_column = ws.max_column or 0
rows = ws.iter_rows(min_row=self.row_offset+1,
max_row=ws_max_row+self.row_offset,
min_col=self.column_offset+1,
max_col=ws_max_column+self.column_offset)

for row in rows:
yield tuple(cell.value for cell in row)
Expand Down
13 changes: 13 additions & 0 deletions petl/test/io/test_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ def test_fromxlsx():
ieq(expect, tbl)
ieq(expect, tbl)

def test_fromxlsx_offset():
filename = pkg_resources.resource_filename(
'petl', 'test/resources/test.xlsx'
)
tbl = fromxlsx(filename, 'Sheet1', row_offset=1, column_offset=1)
print(tbl.lookall())
expect = ((1, None),
(2, None),
(2, None),
(datetime(2012, 1, 1, 0, 0), None))
ieq(expect, tbl)
ieq(expect, tbl)

def test_fromxlsx_nosheet():
filename = pkg_resources.resource_filename(
'petl', 'test/resources/test.xlsx'
Expand Down

0 comments on commit 0d1f1ea

Please sign in to comment.