Skip to content

On load excel - Document properties setCreated error #2331

@gorbertous

Description

@gorbertous

This is:

- [ x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

e.g. $reader = IOFactory::createReaderForFile($some_file_path);
$spreadsheet = $reader->load($some_file_path);

should load excel file, but it fails because the date created is not in a correct format

What is the current behavior?

error: DateTime::__construct(): Failed to parse time string (2021- 9-13T13:24:38Z) at position 4 (-): Unexpected character

What are the steps to reproduce?

Error path : ROOT/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Document/Properties.php
Error thrown - see the code with stars

private static function intOrFloatTimestamp($timestamp)
    {
        if ($timestamp === null) {
            $timestamp = (float) (new DateTime())->format('U');
        } elseif (is_string($timestamp)) {
            if (is_numeric($timestamp)) {
                $timestamp = (float) $timestamp;
            } else {
                $timestamp = preg_replace('/[.][0-9]*$/', '', $timestamp) ?? '';
                **$timestamp = (float) (new DateTime($timestamp))->format('U');**
            }
        }
        return IntOrFloat::evaluate($timestamp);
    }

// add code that show the issue here...
this can be fixed by adding the
$timestamp = date('Y-m-d h:i:s', strtotime($timestamp));

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet 1.18,
PHP 7.4.8
CakePHP 4.2.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions