Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to import data from database to excel
I am using microsoft access database.
I want to copy data from the table with column names and paste it into a excel file.
I try to copy but I got some errors

import openpyxl as op
import pyodbc

con = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=path;')
cr = con.cursor()

loc = (r'path of the excel file')

wb = op.load_workbook(loc)
sheet = wb.create_sheet(0)

cr.execute('select * from  detail')


for row in cr.columns(table='detail'):

for row in result:

Traceback (most recent call last): File "C:/Users/Nick/PycharmProjects/py/venv/", line 21, in <module> sheet.append(rows.column_name) File "C:\Users\Nick\PycharmProjects\py\venv\lib\site-packages\openpyxl\worksheet\", line 661, in append self._invalid_row(iterable) File "C:\Users\Nick\PycharmProjects\py\venv\lib\site-packages\openpyxl\worksheet\", line 792, in _invalid_row type(iterable)) TypeError: Value must be a list, tuple, range or generator, or a dict. Supplied value is <class 'str'>
for row in result:

In that, you need to make a row as List as follows:
for row in result:
listrow = list(row)

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Import data from excel to Teradata steve87bg 3 523 Sep-18-2019, 01:36 PM
Last Post: steve87bg
  Dictionary for Excel Data Ranjirock 0 279 Aug-18-2019, 05:26 PM
Last Post: Ranjirock
  Import and/or read IMC measurement data Squipy 0 226 Aug-11-2019, 02:48 PM
Last Post: Squipy
  iterate read data from excel sheet jp2017 1 335 Jun-19-2019, 07:45 PM
Last Post: micseydel
  Using executemany to import the data Sandy7771989 1 249 Jun-11-2019, 07:45 AM
Last Post: Sandy7771989
  Python validate excel values data types Useruser00 0 568 Apr-08-2019, 01:29 PM
Last Post: Useruser00
  Who converts data when writing to a database with an encoding different from utf8? AlekseyPython 1 364 Mar-04-2019, 08:26 AM
Last Post: DeaD_EyE
  Data in excel Hass 1 456 Nov-30-2018, 03:59 PM
Last Post: nilamo
  Dataframe Data Query Database ab0217 0 522 Oct-16-2018, 02:26 AM
Last Post: ab0217
  data from excel mida1 0 502 Oct-12-2018, 02:02 PM
Last Post: mida1

Forum Jump:

Users browsing this thread: 1 Guest(s)