"Excel found unreadable content in 'test.xlsx'. Do you want to recover
the contents of this workbook? If you trust the source of this
workbook, click Yes."
The relevant piece of code that I am working with is below:
from openpyxl.workbook import Workbook
from openpyxl.style import NumberFormat
wb = Workbook()
ws = wb.create_sheet()
currentCell = ws.cell(row = 1, column = 2)
currentCell.style.number_format.format_code = NumberFormat.FORMAT_TEXT
currentCell.value = '9705E8601'
currentCell.style.number_format.format_code =
NumberFormat.FORMAT_TEXT
wb.save(filename = outputFile)
Cheers, CJ
On Dec 6, 4:53 pm, CJ <cjustinmay...@gmail.com> wrote:
> I am trying to write a text string to a cell . This works well in
> general but when I try and write a string like 9705E8601 (happens to
> be a project account number) excel thinks there is a problem and
> converts the cell to an 'inf'.
> ...[snip]...
> currentCell.value = '9705E8601'
I spent some time experimenting with your code under openpyxl 1.5.6...
normally when there is a string value, it gets written to xl/
sharedStrings.xml in the xlsx zip file.
The problem is that openpyxl is not writing the string if the string
matches this regexp... re.search("\d+E\d+", yourString, re.I)... it
appears to treat your string as a number with a mantissa (i.e. "E"
notation).
I don't know where this is called, but perhaps this much information
would be helpful in tracking down the problem in the code.
Cheers,
\mike