I am using below script to fetch and convert the blob file stored in IBM db2 database using jupyter notebook. The blob file stored in database is in excel format. I am trying from last few days and I am able to fetch and convert the file in excel into my hard disk but when I open that excel the data I am getting is in binary format. I want the excel as it was when stored. Can anyone help me in this.
import ibm_db import ibm_db_dbi connection = ibm_db.connect("DATABASE; HOSTNAME; PORT; PROTOCOL; UID; PWD;","","") conn = ibm_db_dbi.Connection(connection) cur = conn.cursor() def write_file(data, filename): with open(filename, 'wb') as file: file.write(data) def readBLOB(ID,DATA): # data column is in blob data type query = "SELECT DATA FROM FILEDATA WHERE ID= '12345'" cur.execute(query,(ID,)) record = cur.fetchone() write_file(file, 'User'+'.xls') readBLOB(1,"D:\\New folder\\User.xls")