<?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>James Revillini &#187; excel</title>
	<atom:link href="http://james.revillini.com/tag/excel/feed/" rel="self" type="application/rss+xml" />
	<link>http://james.revillini.com</link>
	<description>Say 'no' to styrofoam.</description>
	<lastBuildDate>Sun, 25 Jul 2010 13:03:39 +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>PHP Script: Convert Excel or tab-delimited file to html table</title>
		<link>http://james.revillini.com/2008/01/30/php-script-convert-excel-or-tab-delimited-file-to-html-table/</link>
		<comments>http://james.revillini.com/2008/01/30/php-script-convert-excel-or-tab-delimited-file-to-html-table/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 22:39:15 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[software]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://james.revillini.com/2008/01/30/php-script-convert-excel-or-tab-delimited-file-to-html-table/</guid>
		<description><![CDATA[Here&#8217;s a script which I wrote today while on the jorb.  The purpose was so that someone could copy and paste from an excel spreadsheet into a textarea, click a button, and voila: an html table. The nice thing was that when I pasted Excel data into the textarea, it was tab-delimited with line breaks.  [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a script which I wrote today while on the jorb.  The purpose was so that someone could copy and paste from an excel spreadsheet into a textarea, click a button, and voila: an html table.</p>
<p>The nice thing was that when I pasted Excel data into the textarea, it was tab-delimited with line breaks.  At that point, all I needed to do was some replacements and throw a table wrapper on it.</p>
<p>Here&#8217;s the code for the conversion function (sorry &#8211; i haven&#8217;t installed a php code parser yet to style this more nicely):</p>
<p>&lt;?php<br />
/**<br />
* convert tab delimited file to html table<br />
* @input string tab-delimited text<br />
* found at http://james.revillini.com<br />
* note: you are not required to keep the above copyright notice in this code.<br />
*/<br />
function tabs_to_table($input) {<br />
//define replacement constants<br />
define(&#8216;TAB_REPLACEMENT&#8217;, &#8216;&lt;/td&gt;&lt;td&gt; &#8216;);<br />
define(&#8216;NEWLINE_REPLACEMENT&#8217;, &#8216;&lt;/td&gt;&lt;/tr&gt;&lt;tr%s&gt;&lt;td&gt; &#8216;);<br />
define(&#8216;TABLE_BEGIN&#8217;, &#8216;&lt;table&gt;&lt;tr&gt;&lt;td&gt; &#8216;);<br />
define(&#8216;TABLE_END&#8217;, &#8216;&lt;/td&gt;&lt;tr&gt;&lt;/table&gt;&#8217;);&lt;/code&gt;</p>
<p>//replace all tabs with end-cell, begin-cell<br />
$input = preg_replace  (’/\t/’  , TAB_REPLACEMENT  , $input);</p>
<p>//split the list on linebreaks<br />
$rows = preg_split  (’/\r\n/’  , $input);</p>
<p>//replace all linebreaks with end-row, begin-row (with or without altRow class)<br />
$output = ”;<br />
foreach ($rows as $index =&gt; $row) {<br />
$output .= $row . sprintf(NEWLINE_REPLACEMENT, ($index%2?”:’ class=”alt”‘));<br />
}</p>
<p>//build table<br />
$input = TABLE_BEGIN . $output . TABLE_END;<br />
return ($input);<br />
}<br />
?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://james.revillini.com/2008/01/30/php-script-convert-excel-or-tab-delimited-file-to-html-table/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
