1

I am making an .xlsx file then send it via email. But when I received the file in my email. It says "unreadable content" and try to recover it. When I recover it the file is complete and intact. Nothing is missing. But I don't want that error box to appear.

I am using this line of code because php_zip is not enabled on my server therefore I must use this. Without this I will get an error that says ZipArchive missing or something.

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);

And lastly this is my function to make the excel file:

$objPHPExcel = new PHPExcel();

           $counter = -1; $counterEmpty = 0;
           foreach($user_notifications as $mode => $arrayRawData){
               if(!empty($arrayRawData)){
                   if($counter != -1)
                   {$objPHPExcel->createSheet();}

                    $Header = "A";
                    $Header2 = "A";
                    $HeaderCol = 1;
                    $counter++;
                    $counterEmpty++;

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

                    foreach($arrayRawData as $HwKeyColumn => $arrayHwData){
                       $HeaderCol2 = $HeaderCol;

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

           if($counterEmpty==0)
           {
        $Header2 = "A";
                $HeaderCol = 1;
                $objPHPExcel->setActiveSheetIndex(0)
                           -> setCellValue($Header2 . $HeaderCol, 'No update or errors.');
           }
           else{}

           $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
           $objWriter->save($date.'_SUBCON_'.$vendor_name.'_AUTO_UPDATE_REPORT.xlsx');

A picture of the error of excel enter image description here

pnuts
  • 58,317
  • 11
  • 87
  • 139
aozora
  • 423
  • 3
  • 13
  • Some say it is about trailing spaces. I even tried the ob_clean and exit I read on net. But none solved my problem. – aozora Jul 01 '15 at 08:55
  • Have you tried to debug the data that you are entering to the excel? I.e. do you get the error with each data row you write or with just some special ones (try to generate smaller excel files with smaller number of rows)? Can you reproduce the error by entering a single failing example row as hard coded values? If you got this far without an answer, next step would be to post that example row here :) – ejuhjav Jul 01 '15 at 13:44

0 Answers0