سؤال

Hey,

my question is based on that Topic:
Read excel xlsx file using simplexlsx in php

is there a possibility to catch that Date Format problem within the simplexlsx.class?

cause im using this script for a dynamic xlsx to database script and i hardly can say where i use the Date format or better wich cell has a date format.

So how can i use the unixstamp($excelDateTime) for unknown column within a while or for loop?

function value( $cell ) {
        // Determine data type
        $dataType = (string) $cell['t'];
            switch ($dataType) {

thats the start of the value class... is it possible to add an switch case for datatype "Date"? if yes how?

example:

i got 3 Tables:
1: ID, col1, col2, col3
2: ID, col1, date, col3
3: ID, col1, col2, date

I have an < SELECT > to choose wich one is needed, but ill pass over the type of column, i want to display one of them with the correct Date not the "41928" UNIX-DATE?

Thx so far
regards

هل كانت مفيدة؟

المحلول

The only way to identify a date/time value in a cell is to look at the number format mask.

Function taken almost exactly from PHPExcel:

function isDateTimeFormatCode($pFormatCode = '') {
    // General contains an epoch letter 'e', so we trap for it explicitly here
    if (strtolower($pFormatCode) === 'general')
        return FALSE;
    // Typically number, currency or accounting (or occasionally fraction) formats
    if ((substr($pFormatCode,0,1) == '_') || (substr($pFormatCode,0,2) == '0 ')) {
        return FALSE;
    }
    // Try checking for any of the date formatting characters that don't appear within square braces
    if (preg_match('/(^|\])[^\[]*[eymdHs]/i',$pFormatCode)) {
        // We might also have a format mask containing quoted strings...
        //    we don't want to test for any of our characters within the quoted blocks
        if (strpos($pFormatCode,'"') !== FALSE) {
            $segMatcher = FALSE;
            foreach(explode('"',$pFormatCode) as $subVal) {
                // Only test in alternate array entries (the non-quoted blocks)
                if (($segMatcher = !$segMatcher) &&
                    (preg_match('/(^|\])[^\[]*[eymdHs]/i',$subVal))) {
                    return TRUE;
                }
            }
            return FALSE;
        }
        return TRUE;
    }

    // No date...
    return FALSE;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top