如何在openpyxl中设置或更改表格的默认高度 [英] How to set or change default height of table in openpyxl

查看:358
本文介绍了如何在openpyxl中设置或更改表格的默认高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过openpyxl改变表格高度,我希望一开始默认一个更大的高度值,然后我可以设置自动换行让我的表格更漂亮,但我不知道如何改变默认高度. 到目前为止,我知道改变表格高度的唯一方法是设置 row_dimension[idx].height 的值,但是使用这种方法,高度将被固定,并且一些单词过多的行会溢出单元格想要.

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.

我试图通过更改 sheet_obj.sheet_format.defaultRowHeight = 40 的值来更改默认表格高度,但它似乎只是一个无法更改的固定值

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

推荐答案

不幸的是,您的期望是不正确的.确定列宽或行高是 MS Excel 等应用程序所做的事情,主要是因为它们取决于所使用的设备和操作系统.openpyxl 是仅用于文件格式的库,因此如果您需要更改这些值,则需要编写自己的代码来执行此操作.

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.

这篇关于如何在openpyxl中设置或更改表格的默认高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆