Python:将excel文件添加到access数据库
我正在使用 pyodbc 访问访问(accdb)文件。我想以编程方式将 Excel 工作簿添加到 Access 数据库中,但找不到执行此操作的 API。这是我当前的代码:
import pyodbc
DBFile = r'C:\Documents and Settings\IA.accdb'
conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ='+DBFile)
exFile = r'C:\Documents and Settings\IA_2006.xls'
conn1 = pyodbc.connect('DRIVER={Microsoft Excel Driver \
(*.xls)};DBQ='+exFile,autocommit=True)
cursor = conn.cursor()
####IA_1 is a table within IA.accdb
cursor.execute('select * from IA_1')
row = cursor.fetchone()
####For debugging, print a line
if row:
print row
如何将 Excel 文件(IA_2006.xls)中的数据导入到 IA.accdb 中?
I am using pyodbc to access an access (accdb) file. I want to add an excel workbook into the access database programatically, but cannot find an API to do so. Here is my current code:
import pyodbc
DBFile = r'C:\Documents and Settings\IA.accdb'
conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ='+DBFile)
exFile = r'C:\Documents and Settings\IA_2006.xls'
conn1 = pyodbc.connect('DRIVER={Microsoft Excel Driver \
(*.xls)};DBQ='+exFile,autocommit=True)
cursor = conn.cursor()
####IA_1 is a table within IA.accdb
cursor.execute('select * from IA_1')
row = cursor.fetchone()
####For debugging, print a line
if row:
print row
How should I import the data from the excel file (IA_2006.xls) into the IA.accdb?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来你到了一定程度就放弃了。
不要放弃! :-)
您已连接到 Excel 电子表格,现在您需要阅读它*。
然后您可以插入到您的 MS Access 数据库中,例如:
*如果有疑问,可以通过运行以下命令找到 Excel 工作表名称:
It seems like you got to a certain point and gave up.
Don't give up! :-)
You've made the connection to the Excel spreadsheet, now you need to read it*.
Then you can insert to your MS Access db, e.g.:
*If in doubt, Excel sheet names can be found by running the following: