Is there a way to determine if an excel file was created on Windows or Mac using PHPExcel?

I am using PHPExcel to create an xls template that the user can load and fill out using the data he wants. As you know, Excel saves the date in digital format. I use this function to convert data and return timestamps:

public static function excelToTimestamp($excelDateTime, $isMacExcel=false) {
    $myExcelBaseDate = $isMacExcel ? 24107 : 25569; // 1st jan 1904 or 1st jan 1900
    if (!$isMacExcel && $excelDateTime < 60) {
        //  Adjust for the spurious 29-Feb-1900 (Day 60)
        --$myExcelBaseDate;
    }
    // Perform conversion
    if ($excelDateTime >= 1) {
        $timestampDays = $excelDateTime - $myExcelBaseDate;
        $timestamp = round($timestampDays * 86400);
        if (($timestamp <= PHP_INT_MAX) && ($timestamp >= -PHP_INT_MAX)) {
            $timestamp = intval($timestamp);
        }
    } else {
        $hours = round($excelDateTime * 24);
        $mins = round($excelDateTime * 1440) - round($hours * 60);
        $secs = round($excelDateTime * 86400) - round($hours * 3600) - round($mins * 60);
        $timestamp = (integer) gmmktime($hours, $mins, $secs);
    }
    return $timestamp;
}

The problem is that I have to determine if the file that the user imported into the system using excel for mac or windows was filled in so that I can set the date correctly (Mac uses the 1904 calendar and 1900 for windows).

I would like to know if there is a way to detect it using PHPExcel. If not, I can allow the user to report this using a beacon, perhaps ...

+5
source
1

, , @markBaker, PHPExcel , :

 foreach ($rowLine as $header => $col) {
        if ($header == self::COLUMN_DATE) {
            //transform the excel date value into a datetime object
            $date = PHPExcel_Shared_Date::ExcelToPHPObject($sheetData[$row][$col]);
            $rowLine[$header] = $date->format('m/d/Y');
        }else if ($header == self::COLUMN_HOUR) {
            //transform the excel time value into a datetime object
            $time = PHPExcel_Shared_Date::ExcelToPHPObject($sheetData[$row][$col]);
            $rowLine[$header] = $time->format('H:i');
        }else{
            $rowLine[$header] = $sheetData[$row][$col];
        }
 }
+4

All Articles