Is it possible to delete all BUT duplicate rows?

Topics: Developer Forum, User Forum
May 7, 2014 at 7:11 PM
I'm trying to find a way to delete all BUT the repeated rows in a file, I know it's possible to delete the duplicates on a file using something like this:

$worksheet = $objPHPExcel->getActiveSheet();
    foreach ($worksheet->getRowIterator() as $row) {
        $rowIndex = $row->getRowIndex();
        foreach ($worksheet->getRowIterator($rowIndex + 1) as $testRow) {
            if ($testRow == $row) {
                $worksheet->removeRow($rowIndex);
            }
        }
taken from here
However I need to do pretty much the opposite, delete all the rows that doesn't have any duplicates in the file.

*Why do I need this: The duplicate rows are the intersection between M x M sets with data. It's way easier to do it directly on the file that having to considerate the M x M possible results.*

I'd greatly appreciate any guidance you might offer me.