7

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

2 Answers2

8

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

DaFlai
  • 96
  • 1
  • 2
3

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

Nawfal Serrar
  • 2,213
  • 1
  • 14
  • 22