![]() |
Help | float to Int in xlrd - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Help | float to Int in xlrd (/thread-18313.html) |
Help | float to Int in xlrd - Vinci141 - May-13-2019 Hello, I'd built a SQL generator for a project which reads data from .xlsx file and gives Insert statement as output on screen. The code is working fine except it converts INT to Float in output. I need same data format as input for call fields which can be string, int etc. Please advise on below code i'd created. # Date:13/May/2019 # Created By : Vinil Mehta # Objective: Create SQL(Insert) statements from data provided in excel file. import xlrd excel_sheet = 'test.xlsx' Book1 = xlrd.open_workbook( excel_sheet ) sheet1 = Book1.sheet_by_index( 0 ) print( "Opened Sheet Name:", sheet1.name ) column_headers = sheet1.row_values( 0 ) X = ','.join( str(a) for a in column_headers ) for row in range( 1, sheet1.nrows ): row_data = sheet1.row_values(row) print( 'insert into ' + str( sheet1.name ) + ' (' + X + ') values (' + str( sheet1.row_values( row ) ).strip( '[]' ) + ');' ) |