Cannot load strings which look like exponential format
Created originally on Bitbucket by Anonymous
I have been openpyxl (awesome module) for a few months and I came across a bug where I am trying to write out spreadsheet with a string like '3E4545' and then read it back in. This is with version 1.6.1.
#!python
import openpyxl
# Create a spreadsheet with '3E4545' formatted as a string
wb = openpyxl.Workbook()
wb.get_active_sheet().cell('A1').set_value_explicit('3E4545', 's')
wb.save('test.xlsx')
# Read the spreadsheet back in
wb = openpyxl.load_workbook('test.xlsx')
# This load fails to parse the value as a string
# It prints out the data_type as 'n' and the value as 'inf'
print(wb.get_active_sheet().cell('A1').data_type)
print(wb.get_active_sheet().cell('A1').value)
# This 'inf' is also written out if the spreadsheet is saved again
wb.save('test2.xlsx')
If I then try to open test2.xslx in Excel 2010, it fails with "Excel found unreadable content in test2.xlsx. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes."
In test.xlsx, the value '3E4545' is stored in xl/sharedStrings.xml, so it is clearly a string. It looks like the reader is erroneously interpreting it as a numeric value.