Click to See Complete Forum and Search --> : How to connect Excel with PHP


smchauhan
07-10-2007, 09:32 AM
I want to connect to excel sheet with PHP. If you are aware of please send me the code write answer through this web site....

edit by admin: no contact info on the forum, please. Thank you

hostedconcepts
07-10-2007, 11:38 AM
Converting said Excel sheet to a database would be preferred. However - you could pull it off with the Excel and PHP if needed.

My proposed solution assumes you're on a Windows Platform.

1) Setup the ODBC datasource for the Excel sheet. From the start menu: Settings - Control Panel - Administrative Tools - ODBC. You'll want to setup a "System DSN"

2) Executing SQL on the excel sheet may be a bit tricky - you'll want to play around with these commands on your Excel DSN (assume it's named "excelSheet"):

$conn=odbc_connect('excelSheet','','');
$query="SELECT * FROM sheet1";
$result=odbc_exec($conn,$query);
while (odbc_fetch_row($result))
{
$field1=odbc_result($result,1);
}
odbc_close($conn);

It'll be kinda funky experimenting, as your structure of your excel sheet makes it so even Microsoft's KB doesn't have very good answers to the question of ODBC and Excel.

temp.user123
07-10-2007, 11:48 AM
Save your Excel spreadsheet as a CSV file and then PHP can fgetcsv() just fine. ;)