【问题标题】:Simple XLSX Parser: Date output简单的 XLSX 解析器:日期输出
【发布时间】:2014-04-07 14:42:25
【问题描述】:

嘿,

我的问题基于该主题:
Read excel xlsx file using simplexlsx in php

是否有可能在 simplexlsx.class 中发现日期格式问题?

因为我将此脚本用于动态 xlsx 到数据库脚本,我几乎无法说出我在哪里使用日期格式或更好的单元格具有日期格式。

那么如何在一段时间内或 for 循环中将 unixstamp($excelDateTime) 用于未知列?

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

这就是值类的开始...是否可以为数据类型“日期”添加开关盒?如果是怎么办?

示例:

我有 3 张桌子:
1: ID, col1, col2, col3
2:ID、col1、日期、col3
3:ID、col1、col2、日期

我有一个

谢谢到目前为止
问候

【问题讨论】:

    标签: php excel parsing xlsx


    【解决方案1】:

    在单元格中识别日期/时间值的唯一方法是查看数字格式掩码。

    函数几乎完全取自 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;
    }
    

    【讨论】:

    • 我会尝试将其转移到 SimpleXLSX Parser 但看起来很复杂 Thx Mark ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-24
    • 1970-01-01
    • 2012-04-29
    • 2018-04-18
    • 1970-01-01
    相关资源
    最近更新 更多