Unique Culture

03 Jun, 2009

How to serve Excel files on Google App Engine

Posted by: Sergei Izvorean In: Coding

Google App Engine is a hosting service for your Python and, lately, Java applications. In this case I’m going to talk about Python. Since an application cannot save files it might seem hard to serve an Excel file. Thankfully a great library pyExcelerator is very flexibile and instead of saving a file you can offer a user to download the dynamically generated Excel file. Here is what you do:

from pyExcelerator import *
 
class MainPage(webapp.RequestHandler):
    def get(self):
        wb = Workbook()
        ws0 = wb.add_sheet('Sheet 1')
        # Rows and columns count starts from 0
        for x in range(10):
            for y in range(10):
                # writing to a specific x,y
                ws0.write(x, y, "this is cell %s, %s" % (x,y))
 
        # HTTP headers to force file download
        self.response.headers['Content-Type'] = 'application/ms-excel'
        self.response.headers['Content-Transfer-Encoding'] = 'Binary'
        self.response.headers['Content-disposition'] = 'attachment; filename="workbook.xls"'
 
        # output to user
        wb.save(self.response.out)

Happy coding!

2 Responses to "How to serve Excel files on Google App Engine"

1 | John Machin

September 8th, 2009 at 9:20 am

Avatar

You may like to consider xlwt, a fork of pyExcelerator with bug-fixes and on-going enhancements. See http://pypi.python.org/pypi/xlwt

Comment Form

Categories


  • Jeremy Wallez: Nice post ! For those who needs same functionalities using Java, take a look at http://blog.z80.fr/2010/03/30/google-app-engine/how-to-generate-excel-
  • John Machin: You may like to consider xlwt, a fork of pyExcelerator with bug-fixes and on-going enhancements. See http://pypi.python.org/pypi/xlwt

Flickr PhotoStream

  • the rainbow piano
  • الله البادي ثم اسم بلادي Saudi Malek
  • Mexican fine embroidered ethnic wedding dress
  • Peace Lover Red Mexican embroidered mini dress

About

Web developer @ Eyeflow and Penn State student.