Home >Backend Development >PHP Tutorial > 关于php读取excel有关问题

关于php读取excel有关问题

WBOY
WBOYOriginal
2016-06-13 13:36:01875browse

关于php读取excel问题
用PHP excel类读取excel文件后,如果碰到excel文件的列是日期型的就无法正常显示日期的值。我该怎么让PHP自动判断所读取的列是否是日期型的,如果是日期型就通过转换函数转换成可以正常显示的值。

------解决方案--------------------
这个我做过, 给你个函数, 试一下吧, 以前我在网上找到的

PHP code

//excel日期转换函数
function excelTime($days, $time=false){
    if(is_numeric($days)){
        //based on 1900-1-1
        $jd = GregorianToJD(1, 1, 1970);
        $gregorian = JDToGregorian($jd+intval($days)-25569);
        $myDate = explode('/',$gregorian);
        $myDateStr = str_pad($myDate[2],4,'0', STR_PAD_LEFT)
                ."-".str_pad($myDate[0],2,'0', STR_PAD_LEFT)
                ."-".str_pad($myDate[1],2,'0', STR_PAD_LEFT)
                .($time?" 00:00:00":'');
        return $myDateStr;
    } elseif(strpos($days,'.')!==0) {
        return str_replace('.','-',$days);
    }
    return $days;
} <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn