Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel fill the accents as false

Tags:

php

phpexcel

I have a problem with PHPExcel library 1.7.9 creating a xlsx.

Im using fromArray method to fill a MySQL table into an xlsx, when i try to fill any cell with accents, the cell is filled as "FALSE".

enter image description here

This is my code:

$query="SELECT 
    Caso,
    Etq_Amarilla,
    Tipo,
    Etiqueta,
    'EC Sociedad',
    ProveedorEscalado,
    Proveedor_de_Mantenimiento,
    organizativo,
    OficinaPeople,
    centro,
    sociedad,
    Tipo_Disp,
    Fecha_y_hora_de_creacion,
    Fecha_y_hora_de_cierre,
    domicilio,
    jcentro04,
    analitico,
    DTDT
from CdM_Diario where Dia='5'";

$datos=$mysqli->query($query);
$objPHPExcel->setActiveSheetIndex(4);
$objPHPExcel->getActiveSheet()->fromArray($cabecera,NULL,"A1");
$cont=2;
while($fila=$datos->fetch_assoc())
{
    $objPHPExcel->getActiveSheet()->fromArray($fila,"pepe","A".$cont."");
    $cont++;
}
$cont=2;

Solved with:

$mysqli->set_charset('utf8');

Thanks to Mark Baker

like image 818
Adrián Pulido del Castillo Avatar asked Jan 09 '14 10:01

Adrián Pulido del Castillo


2 Answers

I know it's quite old, but I came across the same today and utf8_encode($row['field']) worked for me.

like image 198
DaFlai Avatar answered Sep 18 '22 00:09

DaFlai


PHPExcel works with UTF-8 charset, you need to use UTF-8 data or convert it before setting it to your object.

 $mysqli->set_charset('utf8');

should do the trick.

credit to @Mark Baker

like image 38
Nawfal Serrar Avatar answered Sep 18 '22 00:09

Nawfal Serrar