Setting column auto_size property - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Setting column auto_size property (/thread-2848.html) |
Setting column auto_size property - volcano63 - Apr-14-2017 Hi, I am creating an Excel workbook using openpyxl. I build the worksheets - which is not a rocket science , but I cannot find a way to set bestFit, auto_size, whatever attribute of columns. I was pointed to dimesions module in documentation - but it allows you to check the attribute, not to set it. I tried browsing styles module - no luck there too. Could anyone please help me out? (To stave questions "what I have tried" - I cannot show anything because I did not find anything worth trying) RE: Setting column auto_size property - Mekire - Apr-15-2017 I have no experience with openpyxl, but glancing at the source here: http://openpyxl.readthedocs.io/en/default/_modules/openpyxl/worksheet/dimensions.html I can see that there are two classes (which inherit from Dimension) which have the arguments you are looking for as attributes. They all have default vaules, but you can also pass them on creation of an instance setting them to whatever you want. RE: Setting column auto_size property - volcano63 - Apr-15-2017 (Apr-15-2017, 11:15 AM)Mekire Wrote: I have no experience with openpyxl, but glancing at the source here: Exactly my problem - it is unclear how they may be connected to sheet, and the documentation specifically states that they are used for querying - not setting (This was the link I failed to include since it was my first post, in this incarnation ) RE: Setting column auto_size property - volcano63 - Apr-15-2017 I tried that sheet = wb.create_sheet(' By '.join((sheet_name, test_type))) sheet.append(columns) for dim in sheet.column_dimensions.values(): dim.bestFit = TrueIt did not work - though by documentation I did not really expect it to |