UTF8-Excel PHP report

0

I have the problem that I do not recognize the special characters, I tried the following but it is not displayed correctly:

My header

header("Content-Type: text/html;charset=utf-8");

Column in which I want you to show me signs, strange characters, etc.

->setCellValue('G' .$i, utf8_encode($row['objetivo']));

I also tried to put it without utf8

->setCellValue('G' .$i, $row['objetivo']);

Header Finals

header('Content-Type: application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Evaluaciones-'.date('Y-m-
d').'.xlsx"');
header('Cache-Control: max-age=0');
    
asked by Noel L 28.09.2017 в 22:06
source

1 answer

0

I would like to see a var_dump ($ results of the DB) of your code, but I did the test and I do not find problems with this example, I leave it complete for you to try it, just change the require_once of your phpToExcel

<?php
require_once(dirname(__FILE__) . '/phpModules/phpToExcel/PHPExcel.php');
require_once(dirname(__FILE__) . '/phpModules/phpToExcel/PHPExcel/IOFactory.php');    

$resultadoDB=[
    ["campo1"=>"texto con caracteres ##$%&/()","campo2"=>"texto normal"],
    ["campo1"=>"Campo con acentos ÄáéíóúÜ ","campo2"=>"xyz"],
];

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$hoja1 = $objPHPExcel->getActiveSheet();
$hoja1->fromArray($resultadoDB, null, 'A1', true);
$hoja1->setTitle('Test');


header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename=Elarchivo.xlsx');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');

Result:

    
answered by 28.09.2017 в 23:10