From ae183d446265cc3f5f5da49426f02c2ba2737079 Mon Sep 17 00:00:00 2001 From: jgvictores Date: Sat, 18 Feb 2017 12:54:59 +0100 Subject: [PATCH] omit empty trailing columns; omit empty rows --- ods2md.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ods2md.py b/ods2md.py index c25878d..bbf71b2 100755 --- a/ods2md.py +++ b/ods2md.py @@ -34,9 +34,24 @@ def main(odf_path): print('##', sheet.name) column_widths = [max(display_len(display_text(cell)) for cell in column) for column in sheet.columns()] + # begin omit empty trailing columns (part 1 of 2) + while column_widths[-1] == 0: + column_widths.pop() + # end omit empty trailing columns (part 1 of 2) for n, row in enumerate(sheet.rows()): + # begin omit empty rows + row_content = '' + for m, cell in enumerate(row): + content = display_text(cell) + row_content += content + if row_content == '': + continue + # end omit empty rows print('|', end=' ') + # begin omit empty trailing columns (part 2 of 2) + del row[len(column_widths):] + # end omit empty trailing columns (part 2 of 2) for m, cell in enumerate(row): content = display_text(cell) disp_len = column_widths[m] + len(content) - display_len(content)