<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Unique Culture &#187; python</title>
	<atom:link href="http://uniqueculture.net/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://uniqueculture.net</link>
	<description>applying technology creatively</description>
	<lastBuildDate>Sun, 28 Nov 2010 04:32:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>How to serve Excel files on Google App Engine</title>
		<link>http://uniqueculture.net/2009/06/how-to-serve-excel-files-on-google-app-engine/</link>
		<comments>http://uniqueculture.net/2009/06/how-to-serve-excel-files-on-google-app-engine/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 14:40:59 +0000</pubDate>
		<dc:creator>Sergei Izvorean</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[app engine]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[pyExcelerator]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://uniqueculture.net/?p=81</guid>
		<description><![CDATA[Google App Engine is a hosting service for your Python and, lately, Java applications. In this case I&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[
<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> 
<p>Google App Engine is a hosting service for your Python and, lately, Java applications. In this case I&#8217;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 <a href="http://sourceforge.net/projects/pyexcelerator" target="new">pyExcelerator</a> 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:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> pyExcelerator <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> MainPage<span style="color: black;">&#40;</span>webapp.<span style="color: black;">RequestHandler</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> get<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        wb = Workbook<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        ws0 = wb.<span style="color: black;">add_sheet</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Sheet 1'</span><span style="color: black;">&#41;</span>
        <span style="color: #808080; font-style: italic;"># Rows and columns count starts from 0</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">for</span> y <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>:
                <span style="color: #808080; font-style: italic;"># writing to a specific x,y</span>
                ws0.<span style="color: black;">write</span><span style="color: black;">&#40;</span>x, y, <span style="color: #483d8b;">&quot;this is cell %s, %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>x,y<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># HTTP headers to force file download</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-Type'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'application/ms-excel'</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-Transfer-Encoding'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'Binary'</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-disposition'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'attachment; filename=&quot;workbook.xls&quot;'</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># output to user</span>
        wb.<span style="color: black;">save</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://uniqueculture.net/2009/06/how-to-serve-excel-files-on-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

