Skip to content

Commit

Permalink
feat: If reset_dimensions is set, recalculate the worksheet's dimensi…
Browse files Browse the repository at this point in the history
…ons. Only reset dimensions if read_only is set.
  • Loading branch information
jpmckinney committed Oct 30, 2023
1 parent 68922e4 commit 9bcf2a1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased
----------
0.3.0 - October 30, 2023
------------------------

* If the ``reset_dimensions`` argument to :meth:`.Table.from_xlsx` is set, recalculate the worksheet's dimensions, instead of assuming that the table's width matches the first row's.
* The ``reset_dimensions`` argument to :meth:`.Table.from_xlsx` is ignored if the ``read_only`` argument is false.
* Add Python 3.8, 3.9, 3.10, 3.11, 3.12 support.
* Drop support for 3.5 (2020-09-13), 3.6 (2021-12-23), 3.7 (2023-06-27).

Expand Down
6 changes: 5 additions & 1 deletion agateexcel/table_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def from_xlsx(cls, path, sheet=None, skip_lines=0, header=True, read_only=True,
The number of rows to skip from the top of the sheet.
:param header:
If :code:`True`, the first row is assumed to contain column names.
:param read_only:
If :code:`True`, the XLSX file is opened in read-only mode, to reduce
memory consumption.
:param reset_dimensions:
If :code:`True`, do not trust the dimensions in the file's properties,
and recalculate them based on the data in the file.
Expand Down Expand Up @@ -69,8 +72,9 @@ def from_xlsx(cls, path, sheet=None, skip_lines=0, header=True, read_only=True,
offset = 0
rows = []

if reset_dimensions:
if read_only and reset_dimensions:
sheet.reset_dimensions()
sheet.calculate_dimension(force=True)

if header:
sheet_header = sheet.iter_rows(min_row=1 + skip_lines, max_row=1 + skip_lines)
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

project = 'agate-excel'
copyright = '2017, Christopher Groskopf'
version = '0.2.5'
version = '0.3.0'
release = version

# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='agate-excel',
version='0.2.5',
version='0.3.0',
description='agate-excel adds read support for Excel files (xls and xlsx) to agate.',
long_description=long_description,
long_description_content_type='text/x-rst',
Expand Down

0 comments on commit 9bcf2a1

Please sign in to comment.