PHPExcel spanish characters in .xls output

Topics: Developer Forum
Mar 3, 2015 at 8:46 PM
Edited Mar 3, 2015 at 8:50 PM

I've been testing this library and it works great, except for the final .xls that is not displaying correctly some Spanish Characters like "áéíóú" and long numbers (it turns into exponencial numbers).

i thought that this chars problem was solved adding this line:
"mysqli_set_charset($Link, 'utf8');//if not by default"
But it seems to not be working... any idea of whats going on?

If de entry is "áéíóú" it displays = áéíó
If the numbers are more than 20 chars it displays = 1,23123E+17

Thanks for reading!

Here is the code of index:
$host='localhost'; $user='m9000207_ficlog'; $pass='*******'; $DataBase='m9000207_ficlog';//define the correct values
// open the connexion to the databases server
$Link=@mysqli_connect($host,$user,$pass,$DataBase) or die('Can\'t connect !');
mysqli_set_charset($Link, 'utf8');//if not by default
//your request
$SQL='SELECT * FROM registros';
$rs=mysqli_query($Link, $SQL);//get the result (ressource)
/** Include PHPExcel */
require_once '../Classes/PHPExcel.php';//change if necessary

// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
while($Trs=mysqli_fetch_assoc($rs)){//extract each record
    $F->setCellValue('A'.$Line, $Trs['user_name'])
        ->setCellValue('B'.$Line, $Trs['user_last'])
        ->setCellValue('C'.$Line, $Trs['pais'])
        ->setCellValue('D'.$Line, $Trs['tel'])
        ->setCellValue('E'.$Line, $Trs['user_email']);//write in the sheet
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/');
header('Content-Disposition: attachment;filename="report.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
Mar 3, 2015 at 10:12 PM
What charset is used for your database table?
Mar 3, 2015 at 10:38 PM
MarkBaker wrote:
What charset is used for your database table?
Hi Mark,

Im using utf8_general_ci

Mar 3, 2015 at 11:46 PM
Edited Mar 3, 2015 at 11:54 PM
This is the type of problem I hate: unable to replicate in any way other than providing non-UTF-8 data to PHPExcel..... if data is UTF-8, there should be no issue.

Can you try issuing
mysqli_query($Link, "SET NAMES 'utf8mb4'");
before your SELECT query?