Named Style fails to retain Alignment attributes on reference
Created originally on Bitbucket by cbornstein (Clare Bornstein)
When declaring a named style, alignment attributes are not retained when the style is referenced in order to assign the named style to a cell. Other attributes appear to function as expected; this issue is limited only to the alignment attribute. My implementation is as follows:
1. Declare a new workbook using a specified function, and assign a named style to be used throughout the program:
#!python
def setupStyles(filename):
wb = Workbook()
#declare header style
headerStyle = NamedStyle(name="headerStyle")
headerStyle.font = Font(bold=True)
bd = Side(style="thin", color="000000")
headerStyle.border = Border(left=bd, top=bd, right=bd, bottom=bd)
headerStyle.alignment = Alignment(horizontal='center', vertical='center', wrap_text=True)
#assign styles to worksheet
wb.add_named_style(headerStyle)
wb.save(filename)
wb.close()
2. Call setupStyles with a designated filename; should create workbook with named style above; load workbook.
#!python
setupStyles(filename)
wb = openpyxl.load_workbook(filename)
3. The following commands return the expected styles assigned in setupStyles.
#!python
print(wb._named_styles['headerStyle'].font)
<openpyxl.styles.fonts.Font object>
Parameters:
name=None, charset=None, family=None, b=True, i=False, strike=None, outline=None, shadow=None, condense=None, color=None, extend=None, sz=None, u=None, vertAlign=None, scheme=None
print(wb._named_styles['headerStyle'].border)
<openpyxl.styles.borders.Border object>
Parameters:
outline=True, diagonalUp=False, diagonalDown=False, start=None, end=None, left=<openpyxl.styles.borders.Side object>
Parameters:
style='thin', color=<openpyxl.styles.colors.Color object>
Parameters:
rgb='00000000', indexed=None, auto=None, theme=None, tint=0.0, type='rgb', right=<openpyxl.styles.borders.Side object>
Parameters:
style='thin', color=<openpyxl.styles.colors.Color object>
Parameters:
rgb='00000000', indexed=None, auto=None, theme=None, tint=0.0, type='rgb', top=<openpyxl.styles.borders.Side object>
Parameters:
style='thin', color=<openpyxl.styles.colors.Color object>
Parameters:
rgb='00000000', indexed=None, auto=None, theme=None, tint=0.0, type='rgb', bottom=<openpyxl.styles.borders.Side object>
Parameters:
style='thin', color=<openpyxl.styles.colors.Color object>
Parameters:
rgb='00000000', indexed=None, auto=None, theme=None, tint=0.0, type='rgb', diagonal=<openpyxl.styles.borders.Side object>
Parameters:
style=None, color=None, vertical=None, horizontal=None
4. The alignment attribute does not return the values assigned in setupStyles; instead shows None assigned to all.
#!python
print(wb._named_styles['headerStyle'].alignment)
<openpyxl.styles.alignment.Alignment object>
Parameters:
horizontal=None, vertical=None, textRotation=0, wrapText=None, shrinkToFit=None, indent=0.0, relativeIndent=0.0, justifyLastLine=None, readingOrder=0.0