<?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>Tortoise IT &#187; Microsoft Excel</title>
	<atom:link href="http://www.sean-barton.co.uk/tag/microsoft-excel/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sean-barton.co.uk</link>
	<description>by Sean Barton, a freelance PHP website developer in Crewe, Cheshire</description>
	<lastBuildDate>Tue, 31 Jan 2012 17:34:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Creating a Downloadable Spreadsheet from PHP</title>
		<link>http://www.sean-barton.co.uk/2009/01/creating-a-downloadable-spreadsheet-from-php/</link>
		<comments>http://www.sean-barton.co.uk/2009/01/creating-a-downloadable-spreadsheet-from-php/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 12:53:21 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Downloadable Spreadsheet]]></category>
		<category><![CDATA[Microsoft Excel]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=183</guid>
		<description><![CDATA[I have written several systems that show data on a page but also provide a CSV download file either through a textarea with formatted data inside to copy and paste or via a download link and creates a file on the fly. I recently decided that this wasn&#8217;t the best way to do it seeing as the people will want to be using Microsoft Excel to view the data. It is possible to write a spreadsheet using PHP and using an example from AppServ I started to do it this way. The original link is included above but here is &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2009/01/creating-a-downloadable-spreadsheet-from-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have written several systems that show data on a page but also provide a CSV download file either through a textarea with formatted data inside to copy and paste or via a download link and creates a file on the fly.</p>
<p>I recently decided that this wasn&#8217;t the best way to do it seeing as the people will want to be using Microsoft Excel to view the data. It is possible to write a spreadsheet using PHP and using an example from <a title="AppServ Excel from PHP Example" href="http://www.appservnetwork.com/modules.php?name=News&amp;file=article&amp;sid=8" target="_blank">AppServ</a> I started to do it this way.</p>
<p>The original link is included above but here is my simplified version with smaller more understandable function naming:</p>
<p>Download the example script here: <a class="downloadlink" href="http://www.sean-barton.co.uk/wp-content/plugins/download-monitor/download.php?id=6" title="Version 1 downloaded 381 times" >XLS from PHP Example (723 bytes)</a></p>
<pre>&lt;?php

function xls_BOF() {
	echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
}

function xls_EOF() {
	echo pack("ss", 0x0A, 0x00);
}

function xls_write_cell($row, $col, $value='') {
	if (is_numeric($value)) {
		echo pack("sssss", 0x203, 14, $row, $col, 0x0);
		$value = pack("d", $value);
	} else {
		$l = strlen($value);
		echo pack("ssssss", 0x204, 8 + $l, $row, $col, 0x0, $l);
	}

	echo $value;
}

// Send Headers to set the Filename and force a download of the contents of the script
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");

 // Put the filename in \"'s if you want it to include spaces
header("Content-Disposition: attachment;filename=" . $filename . ".xls");
header("Content-Transfer-Encoding: binary ");

xlsBOF(); //Start the Spreadsheet

xls_write_cell(0, 1, 'Column 1');
xls_write_cell(0, 2, 'Column 2');
xls_write_cell(0, 3, 'Column 3');

$row = 1;
for ($i=0; $i&lt;2; $i++) {
	xls_write_cell($row, 0, 'Row ' . $row . ' Column ' . $i);
	xls_write_cell($row, 1, 'Row ' . $row . ' Column ' . $i);
	xls_write_cell($row, 2, 'Row ' . $row . ' Column ' . $i);

	$row++;
}

xlsEOF(); //End the Spreadsheet

exit(); //Exit the script after download

?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2009/01/creating-a-downloadable-spreadsheet-from-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 8/23 queries in 0.054 seconds using disk
Object Caching 324/336 objects using disk

Served from: www.sean-barton.co.uk @ 2012-02-08 23:14:33 -->
