import pandas as pd import pyodbc import time # 文件路径及文件名 mdb_file = r"X:\xxx.accdb" driver = '{Microsoft Access Driver (*.mdb, *.accdb)}' cnxn = pyodbc.connect(f'Driver={driver};DBQ={mdb_file}') crsr = cnxn.cursor() # 打印mdb文件中的表名 for table_name in crsr.tables(tableType='TABLE'): print(table_name.table_name) # 假设mdb文件中有一个表名称为 Tbl1 # pandas 读取 dfTable = pd.read_sql("SELECT * FROM xxxx", cnxn) df = pd.DataFrame(dfTable) localtime = time.localtime(time.time())#获取当前时间 ti = time.strftime('%Y%m%d',time.localtime(time.time()))#把获取的时间转换成"年月日格式” df.to_excel('xxxx_%s.xlsx' %(str(ti)), index=False) print("数据导出成功!")
标签:mdb,import,表到,EXCEL,cnxn,ACCESS,pd,time,table From: https://www.cnblogs.com/luoye00/p/16847056.html