I'm doing a query in Sql Server
to bring some numbers and put them in an Excel file (.xls) with the library PHPExcel
.
$consulta = "selec celular FROM clientes where celular <> '' AND
LEN(celular) = '10' AND ind_estado = '1' AND ISNUMERIC(celular) > 0 ORDER
BY celular ASC";
$con1 = sqlsrv_query($conn, $consulta);
To generate the .xls
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator('C')->setTitle('C')-
>setDescription('SMS clientes')->setKeywords('php phpexcel excel')-
>setCategory('SMS clientes');
$objPHPExcel->getActiveSheet()->setTitle('Mensajes');
$i = 2;
while($row = sqlsrv_fetch_array($con1, SQLSRV_FETCH_BOTH))
{
$cliente = "Cliente";
$numeros = $row[0];
$mensaje = $_POST["mensaje"];
$fecha = Date("d/m/Y");
$A = "A".$i;
$B = "B".$i;
$C = "C".$i;
$D = "D".$i;
$E = "E".$i;
$F = "F".$i;
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue($A, $cliente);
$objPHPExcel->getActiveSheet()->setCellValue($B, $numeros);
$objPHPExcel->getActiveSheet()->setCellValue($C, $numeros);
$objPHPExcel->getActiveSheet()->setCellValue($D, $numeros);
$objPHPExcel->getActiveSheet()->setCellValue($E, $mensaje);
$objPHPExcel->getActiveSheet()->setCellValue($F, $fecha);
$i++;
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="Mensajes_Arary.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font
::AUTOSIZE_METHOD_EXACT);
$objWriter->save('php://output');
The excel generates everything well, the columns and correct values, if they are set I am entering $row[0]
which is a cell number in the cells B
, C
and D
what happens is that when I open the excel, I mark the following error:
I know that since Excel
, you can remove this error message with the function Texto en columnas
by removing the tabulation, is there any way to correct it from the programming?
It should be noted that I need to correct it from the programming because this is a file that will be generated several times with variable information and the file will be read by software external to me, I do not know how it works, and with that error I did not read well