<?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>michalisavraam.org blog &#187; excel files</title>
	<atom:link href="http://michalisavraam.org/tag/excel-files/feed/" rel="self" type="application/rss+xml" />
	<link>http://michalisavraam.org</link>
	<description>a spatial web presence</description>
	<lastBuildDate>Mon, 24 May 2010 17:17:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Manipulating Excel files using Python part 2: Writing Excel Files</title>
		<link>http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-2-writing-files/</link>
		<comments>http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-2-writing-files/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 04:50:18 +0000</pubDate>
		<dc:creator>Michalis Avraam</dc:creator>
				<category><![CDATA[Python Points]]></category>
		<category><![CDATA[data manipulation]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[excel files]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[write]]></category>
		<category><![CDATA[writing]]></category>
		<category><![CDATA[xlwd]]></category>

		<guid isPermaLink="false">http://michalisavraam.org/blog/38-blog-entries/58-writing-excel-files-using-python-no-excel-needed</guid>
		<description><![CDATA[Writing Excel files using Python is quite easy, using the xlwt package. Similar to xlrd mentioned in an earlier post, xlwt allows one to write Excel files from scratch using Python.A brief reminded of Excel files (as mentioned in an earlier post) follows, to help people understand how Excel files work.The program stores data in [...]


Related posts:<ol><li><a href='http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-1-reading-files/' rel='bookmark' title='Permanent Link: Manipulating Excel files using Python part 1: Reading Excel Files'>Manipulating Excel files using Python part 1: Reading Excel Files</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Writing Excel files using Python is quite easy, using the <a title="xwt repository" href="https://secure.simplistix.co.uk/svn/xlwt/trunk/">xlwt package</a>. Similar to <a title="xlrd package" href="http://www.lexicon.net/sjmachin/xlrd.htm">xlrd</a> mentioned in an <a title="Reaing Excel files using Python" href="http://michalisavraam.org/blog/38-blog-entries/57-manipulating-excel-files-in-python-no-excel-needed.html">earlier post</a>, xlwt allows one to write Excel files from scratch using Python.<span id="more-22"></span><img class="alignright size-full wp-image-43" title="excelPreview" src="http://michalisavraam.org/wp-content/uploads/2009/06/excelPreview.png" alt="excelPreview" width="461" height="280" />A brief reminded of Excel files (as mentioned in an earlier post) follows, to help people understand how Excel files work.The program stores data in what is called a <strong>Workbook</strong>. Think of this as the file on your computer (the .xls). A Workbook can then have one or more <strong>Sheets</strong>, the little tabs on the bottom left corner usually. Within each Sheet, you can find an arrangement of <strong>Cells</strong> in a matrix form, which are referenced by Column Name and Row Number (so the top left cell is A1, the one directly to its right is A2, the one below is B2, etc. The image should help shed some light if you are not familiar with the concept of spreadsheets.To create your own Excel files using Python, all you need to have is the xlwt package. The workflow for such a process is simple: create a workbook, create a sheet within the workbook, start writing data into the cells of the sheet. Sample code shown below should help you get started quickly and easily.</p>
<pre style="text-align: left;">
<pre class="brush: python;">
import xlwt # Import the package
wbook = xlwt.Workbook() # Create a new workbook
sheet = wbook.add_sheet(&amp;amp;amp;quot;Sample Sheet&amp;amp;amp;quot;) # Create a sheet
data = &amp;amp;amp;quot;Sample data&amp;amp;amp;quot; # Something to write into the sheet
for rowx in range(5):
# Loop through the first five rows
for colx in range(5):
# Loop through the first five columns
# Write the data to rox, column
sheet.write(rowx, colx, data)
# Save our workbook on the harddrive
wbook.save(&amp;amp;amp;quot;myFile.xls&amp;amp;amp;quot;)</pre>
</pre>
<p>And that is all you need. You just created a brand new Excel file called myFile.xls within Python without the use of Excel itself. The file has the first 5 rows and columns filled out with the text &#8220;Sample data&#8221;. It is trivial then to change this so it can save any data you want with a little bit more of Python.</p>
Note: There is a rating embedded within this post, please visit this post to rate it.


<p>Related posts:<ol><li><a href='http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-1-reading-files/' rel='bookmark' title='Permanent Link: Manipulating Excel files using Python part 1: Reading Excel Files'>Manipulating Excel files using Python part 1: Reading Excel Files</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-2-writing-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
