Google app engine Python - Excel file reading

662 views
Skip to first unread message

Nijin Narayanan

unread,
Sep 14, 2010, 2:50:33 AM9/14/10
to python-excel
Hi All,

i am doing a web application in Google app engine using Python .I
installed xlrd in Python 2.7. i need to read a excel file and to save
to app engine data store.
How can i read the excel sheet using xlrd in Google app engine.Plz
provide the code...

Look forward for your kind and quick advice.

Thanking you in advance:)

Michael Jugovich

unread,
Sep 18, 2010, 11:51:09 PM9/18/10
to python...@googlegroups.com
Have you checked out the tutorial on http://www.python-excel.org/ , it is located towards the bottom of the page. 


--
You received this message because you are subscribed to the Google Groups "python-excel" group.
To post to this group, send an email to python...@googlegroups.com.
To unsubscribe from this group, send email to python-excel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/python-excel?hl=en-GB.


Chris Withers

unread,
Sep 24, 2010, 6:31:44 AM9/24/10
to python...@googlegroups.com, Michael Jugovich
On 19/09/2010 04:51, Michael Jugovich wrote:
> Have you checked out the tutorial on http://www.python-excel.org/ , it
> is located towards the bottom of the page.

...and if your problem is how to get xlrd onto an app engine project,
that's a question for an app engine support group.

xlrd is just a standard python package, so you just ened to find how to
get standard python packages into an app engine project.

cheers,

Chris

Nijin Narayanan

unread,
Sep 27, 2010, 10:00:33 AM9/27/10
to python...@googlegroups.com
Hi All :)

I tried to read the excel file using xlrd. But get some error .
Code :
 
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

import xlrd

class UploadFile(webapp.RequestHandler):
  def post(self):

    book = xlrd.open_workbook(self.request.get('file'),'r')
    sheet = book.sheet_by_index(0)
    for counter in range(10): # Loop for five times
     # grab the current row
      rowValues = sheet.row_values(counter,start_colx=0,end_colx=2)
      # Print the values of the row formatted to 10 characters wide
      self.response.out.write(tuple(rowValues))
      self.response.out.write("<br>")

class MainHandler(webapp.RequestHandler):
    def get(self):
        self.response.out.write('''
            <html>
            <head></head>
            <body>            
          <form action="/upload" method="post" enctype="multipart/form-data">
            <div>Myfile:<br><input type="file" name="file" size="50"/></div>

            <div>Description (optional): <input type="text" name="filename" value=""></div>
            <div><input type="submit" value="Upload file"></div>
          </form>
          </body>
          </html>''')

I am getting error that :
Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 513, in __call__
    handler.post(*groups)
  File "C:\Users\Administrator\Documents\temp\test.py", line 30, in post
    book = xlrd.open_workbook(self.request.get('file'),'r')
  File "C:\Users\Administrator\Documents\temp\xlrd\__init__.py", line 425, in open_workbook
    on_demand=on_demand,
  File "C:\Users\Administrator\Documents\temp\xlrd\__init__.py", line 878, in biff2_8_load
    f = open(filename, open_mode)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1205, in __init__
    if not FakeFile.IsFileAccessible(filename):
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1134, in IsFileAccessible
    logical_filename = normcase(os.path.abspath(filename))
  File "C:\Python27\lib\ntpath.py", line 465, in abspath
    path = _getfullpathname(path)
TypeError: must be (buffer overflow), not str


We would really appreciate if you can provide any documents or information regarding to this.
Look forward for your kind and quick advice.
Thanking you in advance:)
--
You received this message because you are subscribed to the Google Groups "python-excel" group.
To post to this group, send an email to python...@googlegroups.com.
To unsubscribe from this group, send email to python-excel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/python-excel?hl=en-GB.




--


Nijin Narayanan
Call Me @ 00919656564191

Find Me On : FacebookTwitterGoogle Buzz
Chat: Google Talk/nij...@gmail.com Skype/nijinbymacht Y! messenger/nijinna...@ymail.com



John Machin

unread,
Sep 27, 2010, 8:00:46 PM9/27/10
to python...@googlegroups.com
On 28/09/2010 12:00 AM, Nijin Narayanan wrote:
> Hi All :)
>
> I tried to read the excel file using xlrd. But get some error .
> Code :
>
> from google.appengine.ext import db
> from google.appengine.api import users
> from google.appengine.ext import webapp
> from google.appengine.ext.webapp.util import run_wsgi_app
>
> import xlrd
>
> class UploadFile(webapp.RequestHandler):
> def post(self):
>
> book = xlrd.open_workbook(self.request.get('file'),'r')

[I know very little about "Google app engine"]

Fact: 1st arg of xlrd.open_workbook is a filename.
Fact: 2nd arg of xlrd.open_workbook is a file or file-like object, to be
used for logging.

Guess: self.request.get('file') is the raw content of an xls file,
uploaded to the gae setver.

Assertion: using 'r' for the 2nd arg is a nonsense

Guess: you haven't read the documentation

Guess: you probably need

book = xlrd.open_workbook(file_contents=self.request.get('file'))

>
> I am getting error that :
>
> Traceback (most recent call last):
> File"C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 513, in __call__
> handler.post(*groups)
> File"C:\Users\Administrator\Documents\temp\test.py", line 30, in post
> book = xlrd.open_workbook(self.request.get('file'),'r')
> File"C:\Users\Administrator\Documents\temp\xlrd\__init__.py", line 425, in open_workbook
> on_demand=on_demand,
> File"C:\Users\Administrator\Documents\temp\xlrd\__init__.py", line 878, in biff2_8_load
> f = open(filename, open_mode)

The first arg of xlrd.open_workbook is being passed to the built_in
open() ...


> File"C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1205, in __init__
> if not FakeFile.IsFileAccessible(filename):

... which seems to have been replaced by gae's own code ...

> File"C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1134, in IsFileAccessible
> logical_filename = normcase(os.path.abspath(filename))
> File"C:\Python27\lib\ntpath.py", line 465, in abspath
> path = _getfullpathname(path)
> TypeError: must be (buffer overflow), not str

This is Python's quaint way of telling you that what you allege to be a
filename is much longer than expected.

>
>
> We would really appreciate if you can provide any documents or
> information regarding to this.

The xlrd documentation is provided with each download, and is available
independently on the web e.g.

https://secure.simplistix.co.uk/svn/xlrd/trunk/xlrd/doc/xlrd.html#__init__.open_workbook-function


Nijin Narayanan

unread,
Sep 28, 2010, 5:25:44 AM9/28/10
to python...@googlegroups.com
Dear John Machin,
Greetings :)

It is working fine...Thank you very much ....

Cheeerss :)




--
You received this message because you are subscribed to the Google Groups "python-excel" group.
To post to this group, send an email to python...@googlegroups.com.
To unsubscribe from this group, send email to python-excel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/python-excel?hl=en-GB.




--


Nijin Narayanan


Find Me On : FacebookTwitterGoogle Buzz

Reply all
Reply to author
Forward
0 new messages