<?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>Bagesh Singh&#039;s Blog &#187; file reader in php</title>
	<atom:link href="http://www.bageshsingh.com/bagesh-blog/tag/file-reader-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bageshsingh.com/bagesh-blog</link>
	<description>Shortest Distance to  Web Solutions &#38; Software Solutions</description>
	<lastBuildDate>Wed, 22 Feb 2012 18:42:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>how to read excel file in php</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/07/how-to-read-excel-file-in-php/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/07/how-to-read-excel-file-in-php/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 17:19:28 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[excel reader]]></category>
		<category><![CDATA[file reader in php]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=619</guid>
		<description><![CDATA[2 Techniques Access the raw Excel Binary File Use the Excel API Both techniques have their advantages and disadvantages as you will see during this presentation Access the raw Excel Binary File &#8211; 1 There is a php library written that can access a raw Excel binary file. Benefits include that it is easy and [...]]]></description>
			<content:encoded><![CDATA[<p>2 Techniques<br />
Access the raw Excel Binary File<br />
Use the Excel API</p>
<p>Both techniques have their advantages and disadvantages as you will see during this presentation<br />
Access the raw Excel Binary File &#8211; 1</p>
<p>There is a php library written that can access a raw Excel binary file. Benefits include that it is easy and straight forward to use, has plenty of documentation and examples, and only has one include file of approximately 800 lines. No need for special php compile flags etc, and can be used straight from the download.<br />
Access the raw Excel Binary File &#8211; 2</p>
<p>sample code<br />
&lt;?php<br />
require_once &#8216;Excel/reader.php&#8217;;</p>
<p>// ExcelFile($filename, $encoding);<br />
$data = new Spreadsheet_Excel_Reader();</p>
<p>// Set output Encoding.<br />
$data-&gt;setOutputEncoding(&#8216;CP1251&#8242;);</p>
<p>$data-&gt;read(&#8216;filename.xls&#8217;);</p>
<p>//display cell in row 3, column 4 (D)<br />
echo $data-&gt;sheets[0]['cells'][3][4];<br />
?&gt;<br />
Access the raw Excel Binary File &#8211; 3</p>
<p>The $data-&gt;sheets[0]['cells'] array has other elements that can be used instead of cells (otherwise it wouldn&#8217;t be an array). You can also use numRows or numCols which returns the number or rows or columns respectivily. cellsinfo contains an array itself in which you can retrieve cell information i.e. background color, formating, cell type (number, character etc), column or rowspan etc&#8230;<br />
Access the raw Excel Binary File &#8211; 4</p>
<p>Important The Excel Reader library can be used on any platform, not just Windows. Some aspects DO NOT work, e.g. Lookup Tables, and there maybe more. You will need to be comfortable with arrays, and understand the alphabet sequence, i.e. D =&gt; 4.</p>
<p>Links<br />
php excel reader<br />
php excel writer</p>
<p>There is a link at openoffice.org for the excel file specification, but I forgot to put that link in. Sorry.<br />
Use the Excel API &#8211; 1</p>
<p>Microsoft have provided an API to access it&#8217;s popular products such as Word, Excel, PowerPoint etc. The language commonly refered to is VBA, and this can be accessed via a COM object. Benefits: The major benefit is that it is provided by the product vendor! Another aspect is that it is fairly intuitive, and the techniques can be ported to other Microsoft products<br />
Use the Excel API &#8211; 2</p>
<p>Sample Code<br />
&lt;?php<br />
$excel_app = new COM(&#8220;Excel.application&#8221;) or Die (&#8220;Did not connect&#8221;);<br />
$Workbook = $excel_app-&gt;Workbooks-&gt;Open(&#8216;filename&#8217;) or Die(&#8216;Did not open filename&#8217;);<br />
$Worksheet = $Workbook-&gt;Worksheets(&#8216;sheet1&#8242;);<br />
$Worksheet-&gt;activate;</p>
<p>$excel_cell = $Worksheet-&gt;Range(&#8216;D3&#8242;);<br />
$excel_cell-&gt;activate;</p>
<p>echo $excel_cell-&gt;value;<br />
&#8230;</p>
<p>Use the Excel API &#8211; 3</p>
<p>Sample Code &#8211; closing off<br />
$Workbook-&gt;Save();<br />
$Workbook-&gt;Saved = true;<br />
$Workbook-&gt;Close;</p>
<p>unset($Worksheet);<br />
unset($Workbook);</p>
<p>$excel_app-&gt;Workbooks-&gt;Close();<br />
$excel_app-&gt;Quit();</p>
<p>unset($excel_app);<br />
?&gt;<br />
Use the Excel API &#8211; 4</p>
<p>There are plenty of API functions available and the documentation is pretty crappy, but with good examples and notes. Anything that you can do in Excel can also be done via the API. This includes lookup tables, formulas, protected sheets etc&#8230;</p>
<p>You will also notice from the example code that you can refer to cell coordinates the same way that you view them in Excel, i.e. D3.</p>
<p>Links<br />
VBA reference &#8211; Excel<br />
Conclusion &#8211; 1</p>
<p>Two methods of accessing an Excel file have been presented tonight. One method was directly accesssing the raw binary, the other was via the API. Accessing the raw binary is a bit of a hack. Microsoft do not provide the file format, but instead you must rely on a third party to provide the information.</p>
<p>Classes that have been written work for simple cases, however more complex situations can not be resolved. The benefit however is that this method can be used on any platform and does not require Excel to be installed.<br />
Conclusion &#8211; 2</p>
<p>Using the Excel API is by far the preferred technique. The API was written by the product vendors, and anything you can do in Excel can be replicated with the API. The Microsoft documentation is pretty crappy, but I&#8217;m sure there are good books in the market that can fill the gap. Understanding the object model means that the techniques can be ported to other office applications.</p>
<p>Using VBA does require Excel to be installed on the server, and if my knowledge is correct this also means you must have a Windows Server.</p>
<div id="seo_alrp_related"><h2>Posts Related to how to read excel file in php</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/creating-word-excel-and-csv-files-with-php/" rel="bookmark">Creating Word, Excel and CSV files with PHP</a></h3><p>Browsing the World Wide Web you can find out various methods of creating files with PHP. In this article we demonstrate several ways to create ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/05/php-file-handling-filesystem-functions-list/" rel="bookmark">PHP File Handling (Filesystem) Functions List</a></h3><p>basename — Returns filename component of path chgrp — Changes file group chmod — Changes file mode chown — Changes file owner clearstatcache — Clears ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/reading-the-clean-text-from-pdf-with-php/" rel="bookmark">Reading the &#8220;clean&#8221; text from PDF with PHP</a></h3><p>Portable Document Format (PDF) is a file format created for the document exchange. Each PDF file encapsulates a complete description of a fixed-layout 2D document ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/hdfc-bank-payment-gateway-code-hdfc-payment-gateway-php-code/" rel="bookmark">HDFC Bank Payment Gateway code, hdfc payment gateway php code</a></h3><p>server, this file is configured to be read only by the Payment Gateway system. This file is used for authenticating the merchants and it contains ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/creating-parsing-json-data-php/" rel="bookmark">Creating and Parsing JSON data with PHP</a></h3><p>I was in a party and a guy came near to me and asked me what is JSON and how can handle it via PHP. ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/07/how-to-read-excel-file-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

