0

I'm writing a python script that will be used to write data to an xls file.

In excel you can format numbers to a decimal place, while keeping the original value. I'm using the xlwt python module to write data, but cannot find anything on this particular topic online.

Is possible to do it with the xlwt module or any other python module?

Here is what exactly I'm talking about:

Here is some sample data

Then I highlighted these cells, right click, and selected format. In the format options, I changed 'decimal places' to 1 (from 2).

As you can see the original value is still stored, although it is formatted.

Formatted cells

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
Mathu
  • 3
  • 3
  • In [Read Excel File in Python](http://stackoverflow.com/questions/22169325/read-excel-file-in-python) there seems to be some focus on reading in variable formats and maybe `openpyxl` has something along that way. and before I have to move on I found [Preserving styles using python's xlrd,xlwt, and xlutils.copy](http://stackoverflow.com/questions/3723793/preserving-styles-using-pythons-xlrd-xlwt-and-xlutils-copy) after a super complicated search session ;-) If you found your solution, please comment here or update your question. Thanks. – Dilettant Jun 16 '16 at 13:29
  • If I understand correctly, the issue is that the numbers you write to the xls file are the "full" values (no truncated decimals). You want the full value in excel, but you want it only to show a certain number of decimals? – nbryans Jun 16 '16 at 13:29
  • Yes that is correct. – Mathu Jun 16 '16 at 13:34
  • Also I will try out the method described in 'Perserving styles using ...' and check if it works. Thanks – Mathu Jun 16 '16 at 13:38
  • You can use xlrd module – khelili miliana Jun 16 '16 at 14:12

0 Answers0