样式化合并单元格区域中最左上方的单元格不会设置所有样式

时间:2019-10-02 07:03:28

标签: python styles openpyxl

我有一个单元格C1:L1,当我尝试对最左边的单元格进行样式设置时,会尝试将其居中对齐并对其进行边框设置。

我尝试使用NamedStyle设置整个工作簿的样式(在合并单元格之前和之后),但仍然只设置了最左边的样式。

from openpyxl.styles import Alignment
from openpyxl.styles import NamedStyle, Border, Side
center = Alignment(horizontal='center', vertical='center')
br = Border(left=Side(style='thick'), 
           right=Side(style='thick'), 
           top=Side(style='thick'), 
           bottom=Side(style='thick'))
ws = file.active
ws.merge_cells('C1:L1')
ws['C1'].value = 'some value' 
ws['C1'].alignment = center #I tried these lines
ws['C1'].border = br        #before and after the merge_cells

0 个答案:

没有答案