Adjusting the Rows and Columns of Excel (openpyxl module):

Setting the height and width of cell in Python for Data Science:

The worksheet objects have row_dimension and column_dimension, which are attributes controlling row heights and column widths. The row_dimensions and the column_dimension of a sheet are similar to values in a dictionary. The row_dimensions contain RowDimension objects and column_dimensions contain ColumnDimension objects. When we use row_dimension, we can access one of the objects using number of rows. In case of column_dimensions, we are able to access one of the objects using letters of the column.

Code 1: Setting the dimensions of the cell

Adjusting the Rows and Columns of Excel in Python for Data Science

OUTPUT:

Merging of cells:

We can merge rectangular area of cells into a single cell by using merge_cells() sheet method. The argument used for merging the cells is a single string of the top left and bottom right cells present in the rectangular area to be merged.

Code 2: Merging of cells

OUTPUT:

Adjusting the Rows and Columns of Excel in Python for Data Science

Unmerging of cells:

In case we need to unmerge the cells, we can call unmerge_cells() sheet method.

Code 3: Unmerging of cells

Adjusting the Rows and Columns of Excel in Python for Data Science

Setting the font styles of cells:

For customizing font styles in cells, we need to import the Font() function from the openpyxl.styles module.

Code 4: Setting font of text

OUTPUT:

Adjusting the Rows and Columns of Excel in Python for Data Science

To learn more about excel in python for data science, you can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.