title: PHPExcel writing strange characters
body: <p>I have a PHP file with a query in sqlsrv, runs well, generated an Excel file with either PHPExcel or without the library, the Excel file is generated either but in the next cell down after writing the results writes strange symbols like this: </p>
  
  <blockquote>
    <p>ÐÏà¡±á;þÿ
    þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿþÿÿÿ</p>
    
    <p>þÿÿÿþÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿþÿà…ŸòùOh«‘+'³Ù0¸@Hh€˜
    ¤°äUntitled SpreadsheetUnknown CreatorUnknown
    Creator@ÐM¦$Ò@ÐM¦$Ò »
    ÌÑB°=¼%r8X"1ÜCalibriàõÿ À àõÿ À àõÿ À àõÿ À
    àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ
    À àõÿ À àõÿ À à À
    “€ÿ’â8ÿÿÿÿÿÿÿÿÿÿÿÿ€€€€€€€€€ÀÀÀ€€€™™ÿ™3fÿÿÌÌÿÿffÿ€€fÌÌÌÿ€ÿÿÿÿÿÿ€€€€€ÿÌÿÌÿÿÌÿÌÿÿ™™Ìÿÿ™ÌÌ™ÿÿÌ™3fÿ3ÌÌ™ÌÿÌÿ™ÿfff™–––3f3™f333™3™3f33™333…d
    WorksheetÁÁgæ®üXNombreDepartamentoFecha12/Oct/2016
    »
    ÌÑ*+‚€Áƒ„ffffffæ?'ffffffæ?(è?)è?¡"dXX333333Ó?333333Ó?U}$
    }$ }$ }$ }$ }$ }$ }$ }$  ý ý
    ý ý ý ý >¶@d‹‹dggÿÿÿÿÿ
    þÿÕÍÕœ.“—+,ù®0¼HPX`hp xŽä
    WorksheetFeuilles de calculRoot Entryÿÿÿÿÿÿÿÿ
    ÀFÐM¦$ÒÐM¦$Ò€SummaryInformation(ÿÿÿÿ
    ÀFèWorkbookÿÿÿÿÿÿÿÿÿÿÿÿ
    ÀFdDocumentSummaryInformation8ÿÿÿÿÿÿÿÿÿÿÿÿ
    ÀFìþÿÿÿþÿÿÿþÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</p>
  </blockquote>
  
  <p>Does anyone know how to fix it? I tested locally, on a remote server, with different versions of PHP and it goes the same....</p>
  
  <p>Here´s the code:</p>
  
  <pre><code>&lt;?php
  
  require_once 'PHPExcel.php';
  require_once 'PHPExcel/IOFactory.php';
  
  $server = "192.168.1.240";
  $info = array("Database"=&gt;"Ariel","UID"=&gt;"sa","PWD"=&gt;"" );
  $conn = sqlsrv_connect($server, $info);
  $param = array('ReturnDatesAsStrings'=&gt; true);
  $opt = array("Scrollable" =&gt; SQLSRV_CURSOR_KEYSET);
  
  $objPHPExcel = new PHPExcel();
  
  $fec1 = $_GET["fecha1"];
  $fec2 = $_GET["fecha2"];
  $suc = $_GET["sucursal"];
  $nom = 'Nombre';
  $per = 'Personal';
  $reg = 'Registro';
  $hreg = 'Hora Registro';
  $con = 'Concepto';
  $fecd = 'Fecha';
  $obs = 'Observaciones';
  $dep = 'Departamento';
  
  $sql = "select personal, (nombre +' '+apellidopaterno+' '+apellidomaterno) as '$nom', departamento as '$dep'
  from personal where nombre like '%$nom%' and estatus = 'Alta' and sucursaltrabajo = '$suc'";
  
  $sql2 = "select (p.nombre +' '+p.apellidopaterno+' '+p.apellidomaterno) as '$nom', ad.personal as '$per',ad.registro as '$reg', ad.horaregistro as '$hreg',ad.concepto as '$con',
  ad.fechad as '$fecd', ad.observaciones as '$obs'
  from asiste a join asisted ad on a.id= ad.id join personal p on p.personal = ad.personal 
  where ad.sucursal = '$suc' and a.fechaemision between '$fec1' and '$fec2' order by ad.personal,ad.fechad";
  
  $query = sqlsrv_query($conn, $sql2);
  
  $query2 = sqlsrv_query($conn, $sql);
  
  $objPHPExcel-&gt;setActiveSheetIndex(0);
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('A3', 'Nombre');
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('B3', $nom);
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('A4', 'Departamento');
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('B4', $dep);
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('H4', 'Fecha');
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('I4', date("d/M/Y"));
  
  echo "&lt;table border='1'&gt;&lt;tr&gt;";
  echo "&lt;th&gt;$nom&lt;/th&gt;";
  echo "&lt;th&gt;$per&lt;/th&gt;";
  echo "&lt;th&gt;$reg&lt;/th&gt;";
  echo "&lt;th&gt;$hreg&lt;/th&gt;";
  echo "&lt;th&gt;$con&lt;/th&gt;";
  echo "&lt;th&gt;$fecd&lt;/th&gt;";
  echo "&lt;th&gt;$obs&lt;/th&gt;";
  
  while ($row = sqlsrv_fetch_array($query)) {
  
      $nom = $row['Nombre'];
      $per = $row['Personal'];
      $reg = $row['Registro'];
      $hreg = $row['Hora Registro'];
      $con = $row['Concepto'];
      $fecd = $row['Fecha'];
      $obs = $row['Observaciones'];
  
      echo "&lt;tr&gt;";
      echo "&lt;th&gt;".$nom."&lt;/th&gt;";
      echo "&lt;td&gt;".$per."&lt;/td&gt;";
      echo "&lt;td&gt;".$reg."&lt;/td&gt;";
      if (!empty($hreg)) {
          echo "&lt;td&gt;".$hreg."&lt;/td&gt;";
      }
      echo "&lt;td&gt;".$con."&lt;/td&gt;";
      if (!empty($fecd)) {
          echo "&lt;td&gt;".$fecd-&gt;format("Y-m-d H:i:s")."&lt;/td&gt;";
      }
      echo "&lt;td&gt;".$obs."&lt;/td&gt;";
  }
  
  echo "&lt;/table&gt;";
  
  //header("Content-Type: application/vnd.ms-excel");
  //header("Expires: 0");
  //header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  //header('content-disposition: attachment;filename="Reporte '.$_GET['fecha1'].'\'\''.$_GET['fecha2'].'.xls"');
  
  header('Content-Type: application/vnd.ms-excel');
  header('content-disposition: attachment;filename="Reporte '.$_GET['fecha1'].'\'\''.$_GET['fecha2'].'.xls"');
  header('Cache-Control: max-age=0');
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  $objWriter-&gt;save('php://output');
  
     sqlsrv_close( $conn);
  ?&gt;
  </code></pre>