Xlrd read number as string

I am trying to read a long number from the xls file (6425871003976), but python continues to translate it before it reads it as a number, not a string (6.42587100398e + 12). Is there any method for reading it directly as a string, even if you are in the xls file, is that a number?

values = sheet.row_values(rownum) 

in the values ​​it is displayed correctly (6425871003976.0), but when I try to execute the values ​​[0], it has already switched to the wrong value.

Decision:

This was my solution using the repr () function:

 if type(values[1]) is float: code_str = repr(values[1]).split(".")[0] else: code_str = values[1] product_code = code_str.strip(' \t\n\r') 
+5
source share
3 answers

This is the same meaning. All this differs in the way the value is printed on the screen. The scientific notation you get is that for printing, the str number is called on it. When you print a list of values, the list's internal __str__ method calls repr for each of its elements. Instead, try print(repr(values[0])) .

+2
source

This is an example that brings the value of the cell (in your case it is int), you need to convert it to a string using the str function

 from openpyxl import load_workbook wb = load_workbook(filename='xls.xlsx', read_only=True) ws = wb['Sheet1'] for row in ws.rows: for cell in row: cell_str=str(cell.value) 
0
source

use print "%d" %(values[0])

% d is used to print integer values

0
source

All Articles