In this following script I'm getting an error that the first 4 rows are empty although I'm using this spreadsheet which contains data.
Please have a look and suggest what the problem might be:
$objPHPExcel = PHPExcel_IOFactory::load($path);
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;
$addedtags=0;
$begin_row=2; // 1st line of data in excel file
for ($row = $begin_row; $row <= $highestRow; $row++) {
$val=array();
for ($col=0; $col < $highestColumnIndex; $col++) {
$cell = $objWorksheet->getCellByColumnAndRow($col, $row);
$val[] = $cell->getValue();
}
if ($val[0]<>'') { //check that row contains data before inserting
$sql1 = sprintf("INSERT INTO ".$dbprefix."terms (name , slug, term_group) VALUES (%s, %s, %s)",
GetSQLValueString($val[0], "text"),
GetSQLValueString($val[1], "text"),
GetSQLValueString(0, "int"));
$result = mysql_query($sql1) or die(mysql_error());
echo '<br />Added: '.$val[0];
} else {
echo '<br />Error: Line '.$row.' was empty...';
}
}
I'm using PHPExcel version 1.7.6.