A
A
Alexis_D2018-05-01 13:13:50
phpspreadsheet
Alexis_D, 2018-05-01 13:13:50

Why does it write this way when exporting from a database to Excel?

5ae83da6ce2b2207146936.jpeg
I am using the PHPExcel library.

require_once 'Classes/PHPExcel.php';
$phpExcel = new PHPExcel();

   $res = array(
  '0' => array(
    'data'	=>	'20.11.2003',
    'name'	=>	'Иванов П.С',
    'mail'	=>	'[email protected]'
    ),
  '1' => array(
    'data'	=>	'20.13.2005',
    'name'	=>	'Сидоров П.А',
    'mail'	=>	'[email protected]'
    ),
  '2' => array(
    'data'	=>	'23.11.2008',
    'name'	=>	'Петров П.С',
    'mail'	=>	'[email protected]'
    )
  );

$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
            ->setLastModifiedBy("Maarten Balliauw")
            ->setTitle("Office 2007 XLSX Test Document")
            ->setSubject("Office 2007 XLSX Test Document")
            ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
            ->setKeywords("office 2007 openxml php")
            ->setCategory("Test result file");
$i = null;
foreach($res as $val)
{
  $i++;
  $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A$i", $val[data]);
  $objPHPExcel->setActiveSheetIndex(0)->setCellValue("B$i", $val[name]);
  $objPHPExcel->setActiveSheetIndex(0)->setCellValue("C$i", $val[mail]);
}


 $objPHPExcel->setActiveSheetIndex(0);
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="stat.xls"');
    header('Cache-Control: max-age=0');
    header('Cache-Control: max-age=1');

    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
    header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
    header ('Pragma: public'); // HTTP/1.0

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save('php://output');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-05-01
@dimonchik2013

patamush this is zip, compressed data, you were drawn to XLS X

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question