Gonsabb
Gonsabb

Reputation: 81

PHPEXCEL how to get cell value even with special characters

When i get the cell value using the function getValue(), it returns false if the cell contains special characters, is there any solution to get the content, even if contains non UTF-8 characters? I'm looking to parse them before call the getValue() function. I will appreciate any kind of help.

$objPHPExcel = $objReader->load($filename);
        $objWorksheet = $objPHPExcel->getActiveSheet();
        $i=0;
        $record = array();

        foreach ($objWorksheet->getRowIterator() as $row) 
        {
            $cellIterator = $row->getCellIterator();
            $cellIterator->setIterateOnlyExistingCells(false);
            foreach ($cellIterator as $cell)
            {
                $val = $cell->getValue();
                // $val returns false or empty string ('') when the cell has special characters like ñ or another one
                $record[$i][] = $val;
            }
            $i++;
            if($i==$vueltas )
                return $record;
        }
        return $record;
    }

I tried with utf8_decode function and str_replace to parse the special characters but nothing happen, it still returning false. I think that is a reader problem but i can't find the code that manage it.

Thanks for the help!

Upvotes: 3

Views: 10445

Answers (1)

Gonsabb
Gonsabb

Reputation: 81

I resolved the problem adding:

$objReader = PHPExcel_IOFactory::createReader('CSV');
$objReader->setInputEncoding('ISO-8859-1');

It was a problem of the header charset information.

Thanks to Mark Baker for the help!

Upvotes: 4

Related Questions