Skip to content

Instantly share code, notes, and snippets.

@gridphp
Created February 15, 2023 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gridphp/3b4484898043ca7725bdcc98eb48f00f to your computer and use it in GitHub Desktop.
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.
// 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