Cannot write to worksheet with numpy.float types

Issue #1187 duplicate
Mark Brown created an issue

In older versions the _bind_value() method in uses instance(value, NUMERIC_TYPES), so a value of type numpy.float64 was correctly recognized as numpy.floating. In the latest version, type(value) is used, numpy.float64 is then compared to numpy.floating, which is not equal.

So it can no longer write numpy.float* into a cell.

Thanks for looking into this and provide a patch.

An example is below:

import numpy                                                                                                                                                                                             
import openpyxl                                                                                                                                                                                          
from openpyxl import Workbook                                                                                                                                                                            

wb = Workbook()                                                                                                                                                                                          
dest_filename = 'empty_book.xlsx'                                                                                                                                                                        
ws1 =                                                                                                                                                                                          
print("Before: ", isinstance(val, numpy.floating), "After: ", type(val) in (numpy.floating,))                                                                                                            
ws1.cell(column=1, row=1, value=val) 

Produce output error message:

Before: True After: False
Traceback (most recent call last):
File "./", line 12, in <module>
ws1.cell(column=1, row=1, value=val)
File "/usr/local/lib/python3.6/site-packages/openpyxl/worksheet/", line 240, in cell
cell.value = value
File "/usr/local/lib/python3.6/site-packages/openpyxl/cell/", line 252, in value
File "/usr/local/lib/python3.6/site-packages/openpyxl/cell/", line 218, in _bind_value
raise ValueError("Cannot convert {0!r} to Excel".format(value))
ValueError: Cannot convert 0.5908632902416832 to Excel

Comments (1)

  1. Log in to comment