diff --git a/datalad_tabby/io/xlsx.py b/datalad_tabby/io/xlsx.py index 1276094..38926c1 100644 --- a/datalad_tabby/io/xlsx.py +++ b/datalad_tabby/io/xlsx.py @@ -95,4 +95,13 @@ def _sheet2tsv(ws: Worksheet, dest: Path): tsvfile, delimiter='\t', ) - writer.writerows(ws.iter_rows(values_only=True)) + + # find the last nonempty row + max_idx = 1 + for i, row in enumerate(ws.iter_rows(values_only=True)): + if any(v is not None for v in row): + max_idx = i + 1 # max row is a 1-based index + + # write tsv, truncating empty rows at the end + writer.writerows(ws.iter_rows(values_only=True, max_row=max_idx)) + diff --git a/datalad_tabby/tests/data/demorecord/tabbydemo_files.tsv b/datalad_tabby/tests/data/demorecord/tabbydemo_files.tsv index 2bf7820..b1c0ba6 100644 --- a/datalad_tabby/tests/data/demorecord/tabbydemo_files.tsv +++ b/datalad_tabby/tests/data/demorecord/tabbydemo_files.tsv @@ -2,7 +2,3 @@ path[POSIX] size[bytes] checksum[md5] url raw/adelie.csv 23755 e7e2be6b203a221949f05e02fcefd853 https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.219.3&entityid=002f3893385f710df69eeebe893144ff raw/gentoo.csv 11263 1549566fb97afa879dc9446edcf2015f https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.220.3&entityid=e03b43c924f226486f2f0ab6709d2381 raw/chinstrap.csv 18872 e4b0710c69297031d63866ce8b888f25 https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.221.2&entityid=fe853aa8f7a59aa84cdd3197619ef462 - - - -