Am 30.11.2012, 01:24 Uhr, schrieb <
did...@gmail.com>:
> Actually, I have this exact problem. An excel file I'm given has values
> in
> it like 3E5 (these are model numbers). The cells within Excel display
> properly, and are formatted as text, but using the "Format cell" power,
> rather than the single leading quote power. When I read them in with
> openpyxl, they are all converting to numbers, so my output becomes 300000
> instead of 3E5.
Unfortunately it looks like the behaviour looks is exactly as expected.
From the cell tests:
def test_numeric(self):
def check_numeric(value):
self.cell.value = value
eq_(self.cell.TYPE_NUMERIC, self.cell.data_type)
values = (42, '4.2', '-42.000', '0', 0, 0.0001, '0.9999',
'99E-02', 1e1, '4', '-1E3', 4, decimal.Decimal('3.14'))
for value in values:
yield check_numeric, value
This is handled by the Cell.value property which always checks the type
when setting runs the regex on strings which will identifies strings with
"e" or "E" surrounded numbers as numbers.
A workaround is to assign directly to cell._value and cell._data_to 's',
but I think it should be possible to set the type in the constructor and
maybe disable type-checking if a type is manually set. Probably need a
dedicated set_typed_value(self, value, data_type) Or maybe simply infer
only if a value does not conform to the existing data_type or is None.
Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel:
+49-211-600-3657
Mobile:
+49-178-782-6226