Skip to content

To prevent cell content not visible due to column width.#5

Open
wbtan7 wants to merge 6 commits intoglexey:masterfrom
wbtan7:master
Open

To prevent cell content not visible due to column width.#5
wbtan7 wants to merge 6 commits intoglexey:masterfrom
wbtan7:master

Conversation

@wbtan7
Copy link

@wbtan7 wbtan7 commented Apr 28, 2020

Usage:

to autofit all column
excel2img.export_img("test.xlsx", "test.png", "Sheet1", None, autofit=True)

to autofit certain range
excel2img.export_img("test.xlsx", "test.png", "Sheet1", None, _af_range="B1:Q5")

Usage:

to autofit all column
excel2img.export_img("test.xlsx", "test.png", "Sheet1", None, autofit=True)

to autofit certain range
excel2img.export_img("test.xlsx", "test.png", "Sheet1", None, _af_range="B1:Q5")
Comment on lines 108 to 112
if autofit is not None:
excel.workbook.Application.Range(rng).Columns.AutoFit()
elif _af_range is not None:
excel.workbook.Application.Range(_af_range).Columns.AutoFit()

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meaning of autofit/_af_range function arguments as implemented is not consistent or intuitive, e.g.:

  • autofit=True, _af_range="A1:B2" will auto-fit everything
  • autofit=False, _af_range=None will auto-fit everything

It would be better to have a single autofit option which you would check for truthiness, to do the autofit. Additionally, if autofit is an instance of str, interpret it as a range to autofit.

(it is ok to still have separate command line options, since argparse doesn't support optional option values)

parser.add_option('-p', '--page', help='pick a page (sheet) by page name. When not specified (and RANGE either not specified or doesn\'t imply a page), first page will be selected')
parser.add_option('-r', '--range', metavar='RANGE', dest='_range', help='pick a range, in Excel notation. When not specified all used cells on a page will be selected')
parser.add_option('-af', '--autofit', help='Autofit the column')
parser.add_option('-afr', '--autofitr', metavar='RANGE', dest='_af_range', help='Autofit the column based on range provided')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better long option name would be --autofit-range

wbtan7 added 5 commits May 4, 2020 14:09
Usage:

to autofit all column
excel2img.export_img("test.xlsx", "test.png", "Sheet1", None, autofit=True)

to autofit certain range
excel2img.export_img("test.xlsx", "test.png", "Sheet1", None, _af_range="B1:Q5")
@wbtan7
Copy link
Author

wbtan7 commented May 4, 2020

Thanks for the comment, I updated the commits, do reply if changes is needed .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants