Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
How to store Excel sheet values in the database
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Vela  
View profile  
 More options Oct 11, 8:32 pm
From: Vela <velapp...@gmail.com>
Date: Sun, 11 Oct 2009 03:32:50 -0700 (PDT)
Local: Sun, Oct 11 2009 8:32 pm
Subject: How to store Excel sheet values in the database
Hi All,

Am trying to add the excel sheet datas into the database.

This the code am using to add the whole excel sheet values to the db.

from xlrd import cellname, cellnameabs, colname ,open_workbook
import sqlite3
book = open_workbook("Cases.xls")
s=book.sheet_by_index(0)
conn = sqlite3.connect('test.db')
c = conn.cursor()
c.execute('''CREATE TABLE exceltable (
   sno TEXT,
   TID TEXT,
   Description TEXT,
   OB TEXT,
   IP TEXT,
   OP TEXT,
   RUN TEXT
)''')
for row in range(s.nrows):

    for col in range(s.ncols):
        Exceldata.append(s.cell(row,col).value)
        print Exceldata
    c.execute('INSERT INTO exceltable VALUES (?,?,?,?,?,?,?)', values)
c.commit()

In Exceldata am having all the values of excel sheet but trying to
split in the loop and adding but it gives an error to me.

Thanks for your help in advance.

Thanks & Regards
vela


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Machin  
View profile  
 More options Oct 11, 10:21 pm
From: John Machin <sjmac...@lexicon.net>
Date: Sun, 11 Oct 2009 23:21:58 +1100
Local: Sun, Oct 11 2009 10:21 pm
Subject: Re: [pyxl] How to store Excel sheet values in the database
On 11/10/2009 9:32 PM, Vela wrote:

Sorry to have to contradict you, but in Exceldata are having absolutely
nothing -- you haven't initialised Exceldata, so your program will abort
the first time it tries to do
     Exceldata.append(something)

Next two problems are that you are using "values" in the
c.execute('INSERT ...') (a) instead of "Exceldata" (b) uninitialised

Fourth problem is that as you are writing one Excel row as one database
row, you don't need "all the values of excel sheet"; you need only the
values in one row at a time.

I suggest that you replace your value-writing code with something
simple, like this:

for row_index in xrange(s.nrows):
     values = s.row_values(row_index)
     print row_index, values
     c.execute('INSERT INTO exceltable VALUES (?,?,?,?,?,?,?)', values)

> but trying to
> split in the loop and adding

What does that mean???

> but it gives an error to me.

I'm not surprised. Are the text of the error message and the traceback
a state secret? If you get a problem with the next version of your code,
please supply
(1) the code that you ran
(2) the traceback
(3) the error message
and don't type any of that from memory; use copy/paste.

Cheers,
John


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google