1

I am looking to automatically pull data from Access to Excel using a python script. Manually, I have to do the following inside Excel:

  1. Click on "Data"--> "from Access". Step 1

  2. Select the Data Source (.accdb) Step 2

  3. Input the credentials for Oracle ODBC Driver Connect Step 3

This fairly easy process inside Excel I would like to automate using a python script. Could you get me an idea how this could be achieved? Could I possibly run a macro from python that does these 3 steps ?

Thanks for your help!

Greetings,

Daniel

1

1 Answer 1

1

Your question has two parts:

  1. Reading an access database; to do so you can use pyodbc to read an access database and run query on it. e.g.:

    import pyodbc
    
    conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=path where you stored the Access file\file name.accdb;')
    cursor = conn.cursor()
    cursor.execute('select * from table name')
    
    for row in cursor.fetchall():
        print (row)
    
  2. Write your data to Excel file; for this you can use XlsxWriter to write excel files:

    import xlsxwriter
    
    workbook = xlsxwriter.Workbook('hello.xlsx')
    worksheet = workbook.add_worksheet()
    
    worksheet.write('A1', 'Hello world')
    
    workbook.close()
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.