Tuesday 11 June 2013

display excel worksheet details in php page using fgetcsv() Function

convert an existing Excel file into a .csv format and keep it in one folder. Write the following code in demo.php page.

<?php
if (($handle = fopen("EmpDetails.csv", "r")) !== FALSE) {
echo"<table border=\"1\"cellspacing=\"0\">";
$row = 1;
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
echo"<tr>";
        for ($c=0; $c < $num; $c++) {
echo"<td>";
            echo$data[$c];
echo"</td>";
        }
echo"</tr>";
$row++;
    }
echo"</table>";
    fclose($handle);
}
?>

No comments: