Squash empty rows and columns. Fix #1.
This commit is contained in:
parent
d9a449d256
commit
c90cbe8642
1 changed files with 21 additions and 10 deletions
31
ods2md.py
31
ods2md.py
|
@ -49,22 +49,33 @@ def main(odf_path):
|
||||||
ods = ezodf.opendoc(odf_path)
|
ods = ezodf.opendoc(odf_path)
|
||||||
|
|
||||||
for sheet in ods.sheets:
|
for sheet in ods.sheets:
|
||||||
print('##', sheet.name)
|
|
||||||
|
|
||||||
column_widths = [max(display_len(display_text(cell)) for cell in column) for column in sheet.columns()]
|
column_widths = [max(display_len(display_text(cell)) for cell in column) for column in sheet.columns()]
|
||||||
|
if not any(column_widths):
|
||||||
|
continue
|
||||||
|
|
||||||
for n, row in enumerate(sheet.rows()):
|
print('##', sheet.name)
|
||||||
print('|', end=' ')
|
printed_header = False
|
||||||
for m, cell in enumerate(row):
|
|
||||||
content = display_text(cell)
|
for row in sheet.rows():
|
||||||
disp_len = column_widths[m] + len(content) - display_len(content)
|
contents = [display_text(cell) for cell in row]
|
||||||
print('{0:<{1}}'.format(content, disp_len), end=' | ')
|
if not any(contents):
|
||||||
|
continue
|
||||||
|
|
||||||
|
print('|', end='')
|
||||||
|
for m, content in enumerate(contents):
|
||||||
|
column_width = column_widths[m]
|
||||||
|
if not column_width:
|
||||||
|
continue
|
||||||
|
disp_len = column_width + len(content) - display_len(content)
|
||||||
|
print(' {0:<{1}}'.format(content, disp_len), end=' |')
|
||||||
print()
|
print()
|
||||||
|
|
||||||
if n == 0:
|
if not printed_header:
|
||||||
|
printed_header = True
|
||||||
print('|', end='')
|
print('|', end='')
|
||||||
for w in column_widths:
|
for w in column_widths:
|
||||||
print(':', '-' * (w+1), '|', sep='', end='')
|
if w:
|
||||||
|
print(':', '-' * (w+1), '|', sep='', end='')
|
||||||
print()
|
print()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue