Horizontal text alignment in openpyxl

后端 未结 4 1392
迷失自我
迷失自我 2021-02-07 05:48

I\'m tryign to change the text alignment to the center of 2 merged sells, I\'ve found some answers that didn\'t work for my case

currentCell = ws.cell(\'A1\')
cu         


        
4条回答
  •  被撕碎了的回忆
    2021-02-07 06:16

    You can achieve this by using Python XlsxWriter library.

    import xlsxwriter
    
    workbook = xlsxwriter.Workbook('example.xlsx')
    worksheet = workbook.add_worksheet()
    
    cell_format = workbook.add_format({'align': 'center'})
    
    worksheet.merge_range('A1:B1', "")
    worksheet.write_rich_string('A1','Example', cell_format)
    
    workbook.close()
    

    Here i have merged cells A1, B1 and added a cell format parameter which includes the align parameter assigned as center.

    enter image description here

提交回复
热议问题