xlrd library in creating csv with actual value not formated value.
eg…
value visible in the cell 87.88
actual value is 87.8786875 , this the value getting printed in csv created.
I have excel file of .xlsx format. formatting_info=True is only supported in .xls file therefore converted my file from .xlsx to xls.
Here is the code used to acesss formating info…
import xlrd
from xlrd import open_workbook
wb = open_workbook(’/E/CornerStonePubTools/DR_POC/PriceFile_20210420.xls’, formatting_info=True)
sheet = wb.sheet_by_name(“List1”)
cell = sheet.cell(6, 2)
print (“cell.xf_index is”, cell.xf_index)
fmt = wb.xf_list[cell.xf_index]
print (“type(fmt) is”, type(fmt))
print
print (“fmt.dump():”)
fmt.dump()
output –
alignment_flag: 0
_background_flag: 0
_border_flag: 0
_font_flag: 0
_format_flag: 1
_protection_flag: 0
alignment (XFAlignment object):
hor_align: 0
indent_level: 0
rotation: 0
shrink_to_fit: 0
text_direction: 0
text_wrapped: 0
vert_align: 2
background (XFBackground object):
background_colour_index: 65
fill_pattern: 0
pattern_colour_index: 64
border (XFBorder object):
bottom_colour_index: 0
bottom_line_style: 0
diag_colour_index: 0
diag_down: 0
diag_line_style: 0
diag_up: 0
left_colour_index: 0
left_line_style: 0
right_colour_index: 0
right_line_style: 0
top_colour_index: 0
top_line_style: 0
font_index: 0
format_key: 4
is_style: 0
lotus_123_prefix: 0
parent_style_index: 0
protection (XFProtection object):
cell_locked: 1
formula_hidden: 0
xf_index: 63
I need help in identifying the precision of the cell so that i can apply that precision on the cell while creating csv.