PHPExcel How to set a date in a cell

I need to put the date in the cell when I look at its format, it looks like * 14/03/01.

The value I set is a simple string, and for this reason, when I get the calculated values, it ignores the entered date, because it compares in the calendar (well, a column with all the dates of the actual year) the date I entered with the dates for setting the correct value corresponding to the entered date.

Is there a way to host the format that Excel expects?

+4
source share
2 answers

MS Excel uses the timestamp value for dates, and then disguises it for display; unformatted string.

02types.php /Examples:

$dateTimeNow = time();    //  Get a Unix/PHP timestamp value for the date/time
$objPHPExcel->getActiveSheet()           // Convert Unix timestamp to a MS Excel 
    ->setCellValue('A9', 'Date/Time')    //  serialized timestamp, and set that as 
    ->setCellValue('B9', 'Date')         //  the cell value
    ->setCellValue(
        'C9', 
        PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )
    );
$objPHPExcel->getActiveSheet()        // Format as date and time
    ->getStyle('C9')
    ->getNumberFormat()
    ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2);

PHPExcel_Shared_Date::PHPToExcel() Unix ( , strtotime()), MS Excel; setFormatCode() , MS Excel, , /

+6
$duree = '08:00:00';
PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() );
$sheet->setCellValueByColumnAndRow($row, $num, $duree);
$sheet->getStyleByColumnAndRow($row, $num)
      ->getNumberFormat()
      ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3);

08:00

+3

Source: https://habr.com/ru/post/1532956/


All Articles