python打开excel数据库_使用python导入excel文件中的mssql数据库数据
我試圖用python導(dǎo)入excel文件中的mssql數(shù)據(jù)庫數(shù)據(jù)。我的數(shù)據(jù)在excel表格中的順序不正確。e、 g它顯示第1列數(shù)據(jù),然后是第3列,第2列,然后是第4列,依此類推。
我使用以下腳本:import pyodbc
import csv
connection = pyodbc.connect("Driver={SQL Server Native Client 11.0};"
"Server=MS-DC-06,49208;"
"Database=****;"
"uid=**;pwd=***")
cursor = connection.cursor()
cursor.execute("select top 10 * from Api_NotificationEntry")
data=cursor.fetchall()
for col in data:
with open('dataTester.csv', 'a', newline='') as fp:
a= csv.writer(fp, delimiter=',')
a.writerow({col[0],col[1]})
cursor.close()
connection.close()
它應(yīng)該顯示這樣的數(shù)據(jù):
^{pr2}$
但在excel表格中顯示如下:Col1 Col2
65509
10
2689
65509
10
2689
65509
2689 10
2689 65509
6218 65509
2689 10
2689 65509
6218 65509
2689 10
2689 11
2689 12
2689 13
2689 14
2689 15
16 2689
8 2673
17 2689
3083 19
總結(jié)
以上是生活随笔為你收集整理的python打开excel数据库_使用python导入excel文件中的mssql数据库数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html表单代码例子_关于React的这
- 下一篇: python中的列表和元组_百度资讯搜索