number_format not consistently applied from styles

Issue #372 resolved
Eric Hurkman
created an issue

number_format does not apply consistently when using Styles on cells on the second or subsequent use of any given number_format. This code demonstrates it:

import openpyxl
from openpyxl.styles import Style, Font

wb = openpyxl.Workbook()
ws = wb.active

# Works; the first time #,### is used
ws['A1'].value = 12311
ws['A1'].style = Style(number_format='#,###', font=Font(color='00AA00'))
print ws['A1'].number_format  # prints #,###

# Does not work; applies the new color but not the number format
ws['A2'].value = 12311
ws['A2'].style = Style(number_format='#,###', font=Font(color='AA00AA'))
print ws['A2'].number_format  # prints #,###

# Works, even though it's a new Style() object it matches A1's style, and works
ws['A3'].value = 12311
ws['A3'].style = Style(number_format='#,###', font=Font(color='00AA00'))
print ws['A3'].number_format

wb.save("tmp/tmp.xlsx")
import os; os.system("open tmp/tmp.xlsx")

All print statements correctly show #,### but the format is not actually applied to the cell.

Comments (3)

  1. Log in to comment