Reputation: 31
I have several strings from a form ($_POST
var), some of them with special chars (ñ, á, é, etc.). When I create the Excel file with these $_POST
vars, all cells print the right information but the ones with special chars prints FALSE
.
Here's a piece of code:
for ($j=1; $j<$_POST["z"]; $j++) {
$fila_despacho = $j+1;
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$fila_despacho, '03')
->setCellValue('B'.$fila_despacho, $_POST["servicio".$j])
->setCellValue('C'.$fila_despacho, trim ($_POST["comuna".$j]))
->setCellValue('D'.$fila_despacho, 1)
->setCellValue('E'.$fila_despacho, trim($_POST["nombre".$j]))
->setCellValue('F'.$fila_despacho, trim($_POST["direccion".$j]))
->setCellValue('G'.$fila_despacho, trim($_POST["num".$j]));
}//endfor
About UTF-8, I don't know how to check that, I'm new at this. Can you tell me how?
Upvotes: 3
Views: 4405
Reputation: 51
Change to UTF-8 before setting the cell value. Use utf8_encode()
. Example:
$objPHPExcel->getActiveSheet()->setCellValue('A1', utf8_encode($descripcion));
Later on you can save the file, for example with:
header('Content-Type: application/vnd.ms-excel; charset=UTF-8');
header("Content-Disposition: attachment;filename='$archivo'");
Upvotes: 5