How to Populate a Website From an Excel Database
The PHP language lets you connect to an Excel spreadsheet, read the data and display the spreadsheet values in a Web page. You use this process when you have an Excel spreadsheet of information such as a list of products and want to display this information to your readers. Loop through each cell in the spreadsheet and use the PHP "echo" statement to display the data.
Instructions
-
-
1
Right-click the PHP for your website that you want to use to display the Excel spreadsheet data. Click "Open With" and select your PHP editor you use to create Web pages.
-
2
Set up the Excel spreadsheet class and assign it to a PHP variable. The following code instantiates the class:
$excel =new Spreadsheet_Excel_Reader();
$excel ->setUTFEncoder('iconv');
$excel ->setOutputEncoding('UTF-8'); -
-
3
Open the file. The following code opens the file named "myfile.xls":
$excel->read("c:\myfile.xls");
-
4
Loop through each cell and display the cell's content on the Web page. The following code shows you how to loop through Excel cells:
foreach($sheet['cells'] as $item)
{
foreach($item as $cell)
{
echo "$cell\t";
}
echo "\n";
}
-
1