I am noob in python but I need to export MySQL table into .xls file using xlwt in python. I succeeded in exporting the table using example from here
but the order of table column in excel and MySQL does not match if there are more than two columns in MySQL table.
Here's a part of the code:
from xlwt import *
import sys
import MySQLdb
table_name='student'
sql_select="SELECT * FROM %s"%table_name
conn1 =MySQLdb.connect(host='localhost',user='root',passwd='',db='test')
cu_select=conn1.cursor(MySQLdb.cursors.DictCursor)
try:
cu_select.execute(sql_select)
except MySQLdb.Error, e:
errInsertSql = "Insert Sql ERROR!! sql is==>%s" %(sql_select)
sys.exit(errInsertSql)
result_set = cu_select.fetchall()'
I tried printing result_set and found that mismatch starts from here. Can anyone help me.