通过python脚本以mm/cm为单位在Excel中调整单元格的宽度和高度 [英] Adjusting cells width and height in excel in mm/cm through python script

查看:525
本文介绍了通过python脚本以mm/cm为单位在Excel中调整单元格的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图寻找它,但是找不到.是否有可能使用openpyxl或xlwt模块以mm或cm的尺寸来调整单元格的宽度,高度?如果是,那么有人可以指出我的脚本命令吗?多谢.

I tried to look for it but couldn't find one. Is there a possibility to adjust the width,height of cells in excel in mm or cm dimensions using openpyxl or xlwt modules? if yes then can someone point me to the commands for scripting? thanks a lot.

推荐答案

使用Openpyxl

设置列宽:

#setting width of column B to 12.25
sheet.column_dimensions['B'].width = float(12.25)

设置行高:

#setting height of row 3 to 33.75
sheet.row_dimensions[3].height = float(33.75)

隐藏列和行

使用尺寸,我们还可以隐藏行和列:

Using the dimensions we can also hide rows and columns:

#Hiding Column B
sheet.column_dimensions['B'].hidden = True

并带有行

#Hiding Row 3
sheet.row_dimensions[3].hidden = True

这篇关于通过python脚本以mm/cm为单位在Excel中调整单元格的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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