Created
February 15, 2023 17:46
-
-
Save gridphp/3b4484898043ca7725bdcc98eb48f00f to your computer and use it in GitHub Desktop.
Date formatting in excel export (line 5-24) to be added in main lib.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if array changes, update it | |
if ($arr !== $def_arr) | |
$objPHPExcel->getActiveSheet()->fromArray($arr, NULL, "A2"); | |
// date formatting in excel 2007 + | |
$excelCol = 'A'; | |
foreach($arr[0] as $k => $v) | |
{ | |
if ($this->get_column($k,"formatter") == "date") | |
{ | |
for($r=1;$r<count($arr);$r++) | |
{ | |
$date = $arr[$r][$k]; | |
$objPHPExcel->getActiveSheet() | |
->setCellValue($excelCol.($r+2), PHPExcel_Shared_Date::PHPToExcel( $date )); | |
$objPHPExcel->getActiveSheet() | |
->getStyle($excelCol.($r+2)) | |
->getNumberFormat() | |
->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2); | |
} | |
} | |
$excelCol++; | |
} | |
// write excel2007 standard xlsx | |
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment