I have a function that I intended to be able to remove duplicate rows in an excel worksheet. I pass it $objPHPExcel which has gone through the following function
function checkExtension($inputFileName) {
if (pathinfo($inputFileName,PATHINFO_EXTENSION) == "csv") {
$inputFileType = 'CSV';
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
return $objPHPExcel = $objReader->load($inputFileName);
} else {
return $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
}
}
The removeDuplicates function is
function removeDuplicates($objPHPExcel) {
$worksheet = $objPHPExcel->getActiveSheet();
foreach ($worksheet->getRowIterator() as $row) {
$rowIndex = $row->getRowIndex();
foreach ($worksheet->getRowIterator($rowIndex + 1) as $testRow) {
if ($testRow == $row) {
$worksheet->removeRow($rowIndex);
}
}
}
$newFileName = 'imports/canx.csv';
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
$objWriter->save($newFileName);
return $objPHPExcel = checkExtension($newFileName);
}
The problem is that canx.csv is the same as the orignal file. i.e no rows are getting removed (I've purposefully put in the duplicate rows into the original).
What am I doing wrong here?
Thanks for any assistance given.