I have used Python 3 to create an Excel (.xlsx) file. Now I want to convert this Excel file to an Access (.accdb) file. I know Access can import Excel file, but I am trying to use Python to automate this.
There are 3 sheets in the Excel file. I have made a connection between Excel and Access but not sure how to insert the sheets/values in the Access file. Thank you so much for your help! Many Thanks!
writer=pd.ExcelWriter('ETABS.xlsx',engine='xlsxwriter')
pointcord.to_excel(writer, sheet_name='Sheet1')
jointreaction.to_excel(writer, sheet_name='Sheet2')
writer.save()
import pyodbc
pyodbc.drivers()
DBFile = r'C:\Users\nyeung\Documents\wsp.codingworkshop.python\ClassNotebooks\ETABS.accdb'
conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ='+DBFile)
exFile = r'C:\Users\nyeung\Documents\wsp.codingworkshop.python\ClassNotebooks\ETABS.xlsx'
conn1 = pyodbc.connect('DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ='+exFile,autocommit=True)
curs1 = conn1.cursor()
# the following returns list of tuples
excel_results = curs1.execute().fetchall()
curs.executemany("INSERT INTO ETABS values (?,?)", excel_results)
conn.commit()
for row in curs1.tables():
print (row.table_name)