Monday, 22 February 2016

How to Read an XLS File in PHPIn Feburary 2016 22,

In Feburary 2016 22,
Go to the PHP Excel Reader download site, and download the package called 'php-excel-reader' (see Resources).
Unzip the downloaded file by double-clicking on it.
Upload the file called 'excel_reader2.php' to your website. Use FTP or your Web hosting service's file upload service to do this. The file should be placed in a folder where your PHP scripts can find it. You can put it in the same folder as the PHP script you wish to read Excel files in, or you can put it in a folder that is in the 'include path.' The 'include path' is a set of folders where you can put files that your PHP script will always be able to find, even if your script is in a totally different place. Your website might have a folder called 'includes' that is in the include path. If it does, put 'excel_reader2.php' there. If it doesn't, put it in the same folder as the PHP scripts with which you wish to use it.
Read an XLS File
Upload an Excel file to use as an example. Create a simple Excel file, and save it as 'example.xls'. Open the file and fill in the first three columns of the first row with the words 'column 1', 'column 2' and 'column 3'. Then on the second row, fill the first three columns with the text '1-1', '2-1' and '3-1'. Then fill the first three columns of the third row with the text '1-2', '2-2' and '3-2'. Save the file and upload it to the same folder where you uploaded excel_reader2.php.
Open your favorite text editor, and save a text file called 'example.php'. This will be your PHP script for this tutorial.
Write your PHP script to open the Excel file, read the table of data and then print the data out in the user's Web browser. Use this code to do it:
rowcount(); $r++) { //walk through each rowfor ($c = 1; $c
colcount(); $c++) { //walk through each column
echo $xls->raw($r, $c) . ' '; //Display the data in that cell
}echo '\n'; //make a new line at the end of each row} echo '
'; //close the HTML we made earlier?>
Save and upload your PHP file to your website. If you were able to put PHP Excel Reader in the include path, you may put your PHP file wherever you wish. If not, put your PHP file in the same folder as PHP Excel Reader.
To check your work, visit example.php in your Web browser. You should see the table of data from your Excel file printed in your browser window.
In Feburary 2016 22,

No comments:

Post a Comment