tablib icon indicating copy to clipboard operation
tablib copied to clipboard

Wrong long int value exported

Open fengsp opened this issue 10 years ago • 2 comments

I have the code:

import tablib

data = tablib.Dataset()
data.headers = ['test_id']

a = 568883383628111872
data.append([a])
with open('test.xls', 'wb') as f:
    f.write(data.xls)

Which produces one xls file with id as 568883383628112000.

fengsp avatar Jun 29 '15 10:06 fengsp

Reproducible directly with newest openpyxl 3.0.0, Python 3.7.4:

from openpyxl import Workbook

wb = Workbook()

# Grab the active worksheet
ws = wb.active

# Data can be assigned directly to cells
ws["A1"] = 568883383628111872

# Save the file
wb.save("sample.xlsx")

Reported to openpyxl:

  • https://bitbucket.org/openpyxl/openpyxl/issues/1355/wrong-long-int-value-exported

hugovk avatar Oct 19 '19 12:10 hugovk

Openpyxl will not fix it as this is an Excel limitation (https://docs.microsoft.com/en-us/office/troubleshoot/excel/long-numbers-incorrectly-in-excel). We could detect such values and force them to str to force a text format for such numbers. To be tested...

claudep avatar Oct 22 '19 08:10 claudep