Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to import data from database to excel
#1
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)
sheet.title="Trial"

cr.execute('select * from  detail')
result=list(cr.fetchall())

sheet.append(cr.column_name)

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

for row in result:
    sheet.append(row)


Error:
Traceback (most recent call last): File "C:/Users/Nick/PycharmProjects/py/venv/excel.py", line 21, in <module> sheet.append(rows.column_name) File "C:\Users\Nick\PycharmProjects\py\venv\lib\site-packages\openpyxl\worksheet\worksheet.py", line 661, in append self._invalid_row(iterable) File "C:\Users\Nick\PycharmProjects\py\venv\lib\site-packages\openpyxl\worksheet\worksheet.py", 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'>
Quote

Top Page

Messages In This Thread
How to import data from database to excel - by nick123 - Jun-14-2019, 04:13 PM

Possibly Related Threads...
Thread Author Replies Views Last Post
  Import data from excel to Teradata steve87bg 3 422 Sep-18-2019, 01:36 PM
Last Post: steve87bg
  Dictionary for Excel Data Ranjirock 0 209 Aug-18-2019, 05:26 PM
Last Post: Ranjirock
  Import and/or read IMC measurement data Squipy 0 172 Aug-11-2019, 02:48 PM
Last Post: Squipy
  iterate read data from excel sheet jp2017 1 294 Jun-19-2019, 07:45 PM
Last Post: micseydel
  Using executemany to import the data Sandy7771989 1 232 Jun-11-2019, 07:45 AM
Last Post: Sandy7771989
  Python validate excel values data types Useruser00 0 476 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 345 Mar-04-2019, 08:26 AM
Last Post: DeaD_EyE
  Data in excel Hass 1 427 Nov-30-2018, 03:59 PM
Last Post: nilamo
  Dataframe Data Query Database ab0217 0 504 Oct-16-2018, 02:26 AM
Last Post: ab0217
  data from excel mida1 0 480 Oct-12-2018, 02:02 PM
Last Post: mida1

Forum Jump:


Users browsing this thread: 1 Guest(s)