<?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>scienceoss.com &#187; xlrd</title>
	<atom:link href="http://scienceoss.com/tags/xlrd/feed/" rel="self" type="application/rss+xml" />
	<link>http://scienceoss.com</link>
	<description>useful tidbits for using open source software in science</description>
	<lastBuildDate>Wed, 26 May 2010 03:34:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Read Excel files from Python</title>
		<link>http://scienceoss.com/read-excel-files-from-python/</link>
		<comments>http://scienceoss.com/read-excel-files-from-python/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 18:04:25 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[xlrd]]></category>

		<guid isPermaLink="false">http://scienceoss.com/read-excel-files-from-python/</guid>
		<description><![CDATA[Use the excellent xlrd package, which works on any platform. That means you can read Excel files from Python in Linux! Example usage: Open the workbook Check the sheet names Get the first sheet either by index or by name Iterate through rows, returning each as a list that you can index: If you just [...]]]></description>
			<content:encoded><![CDATA[<p>Use the excellent <a href="http://www.lexicon.net/sjmachin/xlrd.htm">xlrd</a> package, which works on any platform.  That means you can read Excel files from Python in Linux!  Example usage:</p>
<p>Open the workbook</p>
<pre class="brush: python; title: ; notranslate">import xlrd
wb = xlrd.open_workbook('myworkbook.xls')</pre>
<p>Check the sheet names</p>
<pre class="brush: python; title: ; notranslate">wb.sheet_names()</pre>
<p>Get the first sheet either by index or by name</p>
<pre class="brush: python; title: ; notranslate">sh = wb.sheet_by_index(0)
sh = wb.sheet_by_name(u'Sheet1')</pre>
<p>Iterate through rows, returning each as a list that you can index:</p>
<pre class="brush: python; title: ; notranslate">for rownum in range(sh.nrows):
    print sh.row_values(rownum)</pre>
<p>If you just want the first column:</p>
<pre class="brush: python; title: ; notranslate">first_column = sh.col_values(0)</pre>
<p>Index individual cells:</p>
<pre class="brush: python; title: ; notranslate">cell_A1 = sh.cell(0,0).value
cell_C4 = sh.cell(rowx=3,colx=2).value</pre>
<p>(Note Python indices start at zero but Excel starts at one)</p>
<p>Turns out the <span class="c">put_cell()</span> method isn&#8217;t supported, so ignore the following section (Thanks for the heads up, John!)</p>
<p><strike>Put something in the cell:</p>
<pre class="brush: python; title: ; notranslate">row = 0
col = 0
ctype = 1  # see below
value = 'asdf'
xf = 0  # extended formatting (use 0 to use default)
sh.put_cell(row, col, ctype, value, xf)
sh.cell(0,0)  # text:u'asdf'
sh.cell(0,0).value  # 'asdf'</pre>
<p>Possible ctypes: 0 = empty, 1 = string, 2 = number, 3 = date, 4 = boolean, 5 = error </strike></p>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/read-excel-files-from-python/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
	</channel>
</rss>

