1

Somewhere in my program my phpexcel looks like this:

$objPHPExcel = new PHPExcel();

foreach($arrayRawData as $HwKeyColumn => $arrayHwData){
        $objPHPExcel->setActiveSheetIndex($counter)
                    -> setCellValue($Header2 . $HeaderCol , $HwKeyColumn);
        $objPHPExcel->getActiveSheet()->setTitle($mode);
}

foreach($arrayRawData as $HwKeyColumn => $arrayHwData){

        foreach($arrayHwData as $id => $value){
                $objPHPExcel->setActiveSheetIndex($counter)
                            -> setCellValue($Header . $HeaderCol2,$value);
        }
}

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('Report.xlsx');

I removed the incrementing of cell. It is working correctly. As I manage to save into my Excel with all data intact and no errors in placement.

My problem is in the most inner loop. The $value would for example have a value PHYSICALLY DEFECTIVE˜. But when it saves in the Excel. It is displayed as PHYSICALLY DEFECTIVE. The ~ is missing. I need to also grab that for error trapping purpose.

I tried to echo $value and surely it echoes PHYSICALLY DEFECTIVE˜. I also tried getting the original value of $value and passed it to a new variable. So it now is a new variable with value of PHYSICALLY DEFECTIVE˜ but still when it saves it becomes PHYSICALLY DEFECTIVE.

//edit But when I hardcode it like $value = 'PHYSICALLY DEFECTIVE˜'; The Excell will display correctly. But if I leave it for the loop to change the value of $value it removes ~

pnuts
  • 58,317
  • 11
  • 87
  • 139
aozora
  • 423
  • 3
  • 13
  • Have you tried escaping the character? E.g. $value = 'PHYSICALLY DEFECTIVE\˜'; – Jim Wright Jun 03 '15 at 06:44
  • I should edit what I said in the above. I tried that. And also I feel the problem isn't there. because if I hardcode it like $value = 'PHYSICALLY DEFECTIVE~'; then feed it to value. The output is PHYSICALLY DEFECTIVE~ But when I use the loop it goes back to PHYSICALLY DEFECTIVE only – aozora Jun 03 '15 at 06:55
  • What encoding are you using? PHPExcel supports UTF-8. – Jim Wright Jun 03 '15 at 07:01
  • I have this in my header header("content-type:application/csv;charset=UTF-8"); – aozora Jun 03 '15 at 07:25
  • Origin of `$arrayRawData`, there's something wrong with encoding. – Serge Seredenko Sep 04 '15 at 04:08

0 Answers0