openpyxl中的水平文本对齐 [英] Horizontal text alignment in openpyxl
本文介绍了openpyxl中的水平文本对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将文本对齐方式更改为 2 个合并销售的中心,我发现了一些对我的案例不起作用的答案
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')
currentCell.style.alignment.horizontal = 'center' #TypeError: cannot set horizontal attribute
#or
currentCell.style.alignment.vertical = Alignment.HORIZONTAL_CENTER #AttributeError: type object 'Alignment' has no attribute 'HORIZONTAL_CENTER'
两者都不起作用,还有其他方法吗?
both didn't work, is there any other ways to do it?
推荐答案
是的,openpyxl 有一种方法可以做到这一点:
yes, there is a way to do this with openpyxl:
from openpyxl.styles import Alignment
currentCell = ws.cell('A1') #or currentCell = ws['A1']
currentCell.alignment = Alignment(horizontal='center')
希望对你有帮助
这篇关于openpyxl中的水平文本对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文