I have this code I found and it works great except for it imports all the worksheets into my MySql db and I only wnat the first worksheet.
<?php
$connect = mysqli_connect("localhost", "root", "", "test_db");
include ("PHPExcel/IOFactory.php");
$html="<table border='1'>";
$objPHPExcel = PHPExcel_IOFactory::load('example.xls');
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
for ($row=2; $row<=$highestRow; $row++)
{
$html.="<tr>";
$name = mysqli_real_escape_string($connect, $worksheet- >getCellByColumnAndRow(0, $row)->getValue());
$email = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(1, $row)->getValue());
$sql = "INSERT INTO tbl_excel(excel_name, excel_email) VALUES ('".$name."', '".$email."')";
mysqli_query($connect, $sql);
$html.= '<td>'.$name.'</td>';
$html .= '<td>'.$email.'</td>';
$html .= "</tr>";
}
}
$html .= '</table>';
echo $html;
echo '<br />Data Inserted';
?>
I have tried $objWorksheet = $objPHPExcel->setActiveSheetIndex(0); as well as getSheet(0); and many other things to no avail.