Answer the question
In order to leave comments, you need to log in
Why does it write this way when exporting from a database to Excel?
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question