我试图在openpyxl中对齐一列,但没有成功:
wb = Workbook()
ws = wb.active
....
ws.column_dimensions["A"].alignment = Alignment(horizontal='left')
ws.column_dimensions["C"].alignment = Alignment(horizontal='center')
相同:
ws["A"].alignment = Alignment(horizontal='left')
ws["C"].alignment = Alignment(horizontal='center')
这对我不起作用。否则,遍历单元格并进行对齐将正常工作!
您应该获得失败的回溯!如果您发布问题,请向我们显示!
ws["A"].alignment = Alignment(horizontal='left')
AttributeError: 'tuple' object has no attribute 'alignment'
for row in rows:
cell_A = row[:1][0]
cell_A.alignment = Alignment(horizontal='left')
经过Python:3.4.2测试-openpyxl:2.4.1-LibreOffice:4.3.3.2