Sheet row_dimensions objects have row_dimensions and column_dimensions that control the row height and column width. row_dimensions and column_dimensions are dictionary values; row_dimensions contains RowDimension objects and column_dimensions contains ColumnDimension objects. In row_dimensions, one of the objects can be accessed using the row number (in this case 1 or 2). In column_dimensions, you can access one of the objects using the letter of the column (in this case, A or B).
Code # 1: Program for setting cell sizes.
# importing the openpyxl module
import openpyxl
# Calling the Workbook () function from openpyxl # create a new blank Workbook object
wb = openpyxl.Workbook ()
# Get worksheet of active sheet # from active attribute.
A rectangular area of cells can be merged into one cell using the merge_cells () worksheet method. The argument for merge_cells () is one line of the top-left and bottom-right cells of the rectangular region to be merged.
Code # 2: Program to merge cells.
import openpyxl
wb = openpyxl.Workbook ()
sheet = wb.active
# merge cell A2 to D4 ie # A2, B2, C2, D2, A3, B3, C3, D3, A4, B4, C4 and D4. # A2: D4 & # 39; combines 12 cells into one cell.