Web Based Spreadsheet with CherryPy and XLWT

15 Nov

An example of a simple spreadsheet through the web. Uses a Table and Form.

The code:

import cherrypy
from cherrypy.lib.static import serve_file
import xlwt

class SHP(object):

def index(self):
return “””<HTML><HEAD><TITLE>SPREADSHEET</TITLE></HEAD>
<BODY><FORM NAME=’sheet’ action=’paul’>
<table border=’1′>
<tr><td><input type=”text” name=”r0c0″></td><td><input type=”text” name=”r0c1″></td><td><input type=”text” name=”r0c2″></td></tr>
<tr><td><input type=”text” name=”r1c0″></td><td><input type=”text” name=”r1c1″></td><td><input type=”text” name=”r1c2″></td></tr>
<tr><td><input type=”text” name=”r2c0″></td><td><input type=”text” name=”r2c1″></td><td><input type=”text” name=”r2c2″></td></tr>
</table><BR>
<input type=’submit’ Value=’SUBMIT’>”””

index.exposed = True

def paul(self,r0c0,r0c1,r0c2,r1c0,r1c1,r1c2,r2c0,r2c1,r2c2):
wb=xlwt.Workbook()
ws=wb.add_sheet(‘Web Sheet’)
ws.write(0,0,r0c0)
ws.write(0,1,r0c1)
ws.write(0,2,xlwt.Formula(r0c2))
ws.write(1,0,r1c0)
ws.write(1,1,r1c1)
ws.write(1,2,xlwt.Formula(r1c2))
ws.write(2,0,r2c0)
ws.write(2,1,r2c1)
ws.write(2,2,xlwt.Formula(r2c2))
wb.save(‘Spreadsheet.xls’)

return “Download Spreadsheet: <a href=’/get?filepath=C:\Documents and Settings\user\Desktop\Spreadsheet.xls’>Your Spreadsheet</a>”

paul.exposed = True

def get(self, filepath):
return serve_file(filepath, “application/x-download”, “attachment”)
get.exposed = True

cherrypy.config.update({‘server.socket_host’: ‘127.0.0.1’,
‘server.socket_port’: 8000,
})

cherrypy.quickstart(SHP())

Advertisements

One Response to “Web Based Spreadsheet with CherryPy and XLWT”

  1. http://yahoo.com February 11, 2013 at 6:53 pm #

    “Web Based Spreadsheet with CherryPy and XLWT Architecture and Planning” was a terrific blog post, can not wait to read through a lot more of your postings.
    Time to squander a lot of time online lmao. I appreciate it -Quyen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: