簡體   English   中英

在Excel中導入MySQL表

[英]Importing mysql table in excel

我在python中是菜鳥,但是我需要在python中使用xlwt將MySQL表導出到.xls文件。 我從這里使用示例成功導出了表格

http://ryrobes.com/featured-articles/using-xlwt-and-python-to-export-an-oracle-dataset-to-excel-python-simple-etl-part-2/

但是如果MySQL表中的列多於兩列,則excel和MySQL中表列的順序不匹配。

這是代碼的一部分:

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()'

我嘗試打印result_set,發現不匹配從這里開始。 誰能幫我。

表是按字母順序或按升序組織的,如果要組織順序,請改用行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM