current position:Home>How to set the width and height of Python operation table

How to set the width and height of Python operation table

2022-05-15 05:35:34A small pit of goods

#  Import the form plug-in used openpyxl , have access to pip install openpyxl
import openpyxl

def set_column_width_height_openpyxl(filepath: str,sheetname:str, column_list: list, row_list: list, width: float,
                                     height: float):
    """ @Description: openpyxl Set width and height  :param filepath xlsx File path  :param sheetname sheet name  :param column_list  List name  :param row_list  Row list  :param width  Column width  :param height  Column height  """
    #  Set width and height 
    wb = openpyxl.load_workbook(filepath)
    ws = wb[sheetname]
    #  Adjust column width 
    if len(column_list) > 0:
        for column in column_list:
            #  Set width 
            ws.column_dimensions[column].width = width
    if len(row_list) > 0:
        for row in row_list:
            #  Set height 
            ws.row_dimensions[row].height = height

This method is limited to plug-ins openpyxl Table operation of .

If there is a mistake , Comments or private letters are welcome to point out

copyright notice
author[A small pit of goods],Please bring the original link to reprint, thank you.

Random recommended