Description
>>> arr = ndtest('a=10E01,10E03')
>>> arr.to_excel()
produces something like:
a | 1.00E+02 | 1.00E+04
| 0 | 1
This is not a visual transformation, it actually converts the values to numbers (whatever the actual dtype of labels were -- .dump() converts numpy types to raw Python types anyway)
>>> arr.a.labels.dtype
dtype('<U5')
>>> arr.dump()
[['a', '10E01', '10E03'], ['', 0, 1]]
The solution is to set NumberFormat on the target cells before pasting the values (xlwings/xlwings#436).
>>> wb = open_excel()
>>> # produces bad result
>>> wb[0]['A1'] = '10E03'
>>> # produces good result
>>> wb[0]['A2'].api.NumberFormat = "@"
>>> wb[0]['A2'] = '10E03'
Note that set_labels (currently) returns object arrays. This should be irrelevant when we go via .dump(), which is always the case, I think (when using wb[0] = array
, .dump() is called automatically).
>>> ndtest(3).set_labels('a', {'a1': '10E03'}).a.labels.dtype
dtype('O')
Ideally, this should be fixed in xlwings.
Honestly, this issue seems easy to fix for small arrays (by scanning through each value and setting the format accordingly) but hard to do efficiently (set the format in chunks). Maybe .dump should not return a simple list of list but a custom object which retains the notion of axes etc. so that we can set the format for each axis in a single operation?