Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 843
Muhammad Abdul Ahad Rafiq Avatar asked Oct 18 '22 13:10

Muhammad Abdul Ahad Rafiq


1 Answers

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
like image 80
foxyblue Avatar answered Oct 21 '22 06:10

foxyblue