How to set or change default height of table in openpyxl

℡╲_俬逩灬. 提交于 2019-12-11 15:58:14

问题


I want to change table height by openpyxl,and I wish a more large height value as default at first,then I can set auto wrap line to make my table more beautiful,but I don't know How To Change Default Height.The only way I know so far to change table height is setting the value of row_dimension[idx].height but with this method ,the height will be fixed and some lines with too many words will overflow the cell which isn't what I want.

I have tried to change default table height by changing the value of the sheet_obj.sheet_format.defaultRowHeight = 40 but it seems its just a fixed value which can't be changed

#this way get the fixed height
for i,_ in enumerate(collection_sheet.rows):
        collection_sheet.row_dimensions[i+1].height=60

#this way didn't work
    collection_sheet.sheet_format.defaultRowHeight = 60

I expect all cell with a default height value and auto wrap line will finally determine the height of each row


回答1:


Your expectation is, unfortunately, incorrect. Determining column widths or row heights is something that applications such as MS Excel do, largely because they are dependent upon the device and operating system being used. openpyxl is a library for the file format only, so if you need to change those values you will need to write your own code to do this.



来源:https://stackoverflow.com/questions/56595131/how-to-set-or-change-default-height-of-table-in-openpyxl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!