Adjusting cells width and height in excel in mm/cm through python script

大兔子大兔子 提交于 2019-12-24 03:38:13

问题


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.


回答1:


With Openpyxl

To set column width:

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

To set Row height:

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

Hiding Columns and Rows

Using the dimensions we can also hide rows and columns:

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

And with rows

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


来源:https://stackoverflow.com/questions/43611920/adjusting-cells-width-and-height-in-excel-in-mm-cm-through-python-script

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