0

When a number is long in my excel document, Excel formats the cell value to scientific notation (ex 1.234567e+5) while the true number still exists in the formula bar at the top of the document (ex 123456789012).

I want to convert this number to a string for my own purposes, but when I do, the scientific notation is captured, rather than the true number. How can I assure that it's the true number that is being converted to a string?

Maria
  • 11
  • 1
  • 3
  • 1
    What about converting it to a an `int` first and then making it a `str` – Aditya Patel May 02 '19 at 20:17
  • Have you tried [these](https://stackoverflow.com/questions/22613272/how-to-access-the-real-value-of-a-cell-using-the-openpyxl-module-for-python) answers? – Andrew Allen May 02 '19 at 21:51
  • I have tried the answers you mentioned @AndrewAllen but unfortunately data_type=true isn't what I need, and internal_values is no longer in the openpyxl library. – Maria May 02 '19 at 22:41
  • @AdityaPatel Having some difficulty with this solution as well, but it may be an excel thing I need to work around. It seems excel truncates or rounds numbers that are greater than 15 digits in length. That means once I convert it back to a string it is still an inaccurate number. Will try to find a workaround. – Maria May 02 '19 at 22:53

1 Answers1

0

Python will ignore the formatting that Excel uses for anything other than dates and times, so you should just be able to convert the number to a string. You will, however, be limited by Excel's precision. The OOXML file format is not suitable for some tasks notably those with historical dates or high precision times.

Charlie Clark
  • 18,477
  • 4
  • 49
  • 55