Skip to content

Commit

Permalink
feat: Make reset_dimensions opt-in via a --reset-dimensions option, #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Oct 23, 2023
1 parent d701fe7 commit 3967db9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Unreleased
----------

fix: :doc:`/scripts/in2csv` `recalculates <https://openpyxl.readthedocs.io/en/stable/optimized.html#worksheet-dimensions>`_ the dimensions of an XLSX file, instead of trusting the file's metadata.
* :doc:`/scripts/in2csv` adds a :code:`--reset-dimensions` option to `recalculate <https://openpyxl.readthedocs.io/en/stable/optimized.html#worksheet-dimensions>`_ the dimensions of an XLSX file, instead of trusting the file's metadata.

1.3.0 - October 18, 2023
------------------------
Expand Down
11 changes: 9 additions & 2 deletions csvkit/utilities/in2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def add_arguments(self):
self.argparser.add_argument(
'--use-sheet-names', dest='use_sheet_names', action='store_true',
help='Use the sheet names as file names when --write-sheets is set.')
self.argparser.add_argument(
'--reset-dimensions', dest='reset_dimensions', action='store_true',
help='Ignore the sheet dimensions provided by the XLSX file.')
self.argparser.add_argument(
'--encoding-xls', dest='encoding_xls',
help='Specify the encoding of the input XLS file.')
Expand Down Expand Up @@ -155,7 +158,9 @@ def main(self):
table = agate.Table.from_xls(self.input_file, sheet=self.args.sheet,
encoding_override=self.args.encoding_xls, **kwargs)
elif filetype == 'xlsx':
table = agate.Table.from_xlsx(self.input_file, sheet=self.args.sheet, reset_dimensions=True, **kwargs)
table = agate.Table.from_xlsx(
self.input_file, sheet=self.args.sheet, reset_dimensions=self.args.reset_dimensions, **kwargs
)
elif filetype == 'dbf':
if not hasattr(self.input_file, 'name'):
raise ValueError('DBF files can not be converted from stdin. You must pass a filename.')
Expand All @@ -177,7 +182,9 @@ def main(self):
tables = agate.Table.from_xls(self.input_file, sheet=sheets,
encoding_override=self.args.encoding_xls, **kwargs)
elif filetype == 'xlsx':
tables = agate.Table.from_xlsx(self.input_file, sheet=sheets, reset_dimensions=True, **kwargs)
tables = agate.Table.from_xlsx(
self.input_file, sheet=sheets, reset_dimensions=self.args.reset_dimensions, **kwargs
)

base = splitext(self.input_file.name)[0]
for i, (sheet_name, table) in enumerate(tables.items()):
Expand Down

0 comments on commit 3967db9

Please sign in to comment.