Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhpOffice\PhpSpreadsheet\Exception: Invalid datatype: d #2373

Closed
ClCfe opened this issue Nov 5, 2021 · 3 comments · Fixed by #2485
Closed

PhpOffice\PhpSpreadsheet\Exception: Invalid datatype: d #2373

ClCfe opened this issue Nov 5, 2021 · 3 comments · Fixed by #2485

Comments

@ClCfe
Copy link

ClCfe commented Nov 5, 2021

Hello

I am using v1.19.0
I am openning an existing Xlsx file and I want to write something in a new sheet

The following error occurs:

type: PhpOffice\PhpSpreadsheet\Exception
file: /opt/PhpSpreadsheet/src/PhpSpreadsheet/Cell/Cell.php
line: 233
message: Invalid datatype: d
trace: 
#0 /opt/PhpSpreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php(828): PhpOffice\PhpSpreadsheet\Cell\Cell->setValueExplicit('2021-03-29', 'd')
#1 myscript.php(xxx): PhpOffice\PhpSpreadsheet\Reader\Xlsx->load('...')

I can share the file in private

@ziming
Copy link

ziming commented Nov 17, 2021

My generated excel file had errors on a certain sheet after the latest patch 1.19.0 too

@alfilipe
Copy link

alfilipe commented Nov 18, 2021

Hi all

I'm facing the same issue trying to load a xlsx file

what I've done to correct it is to add the datatype on the file \PhpOffice\PhpSpreadsheet\Cell\DataType const TYPE_DATETIME = 'd';
and on the file \PhpOffice\PhpSpreadsheet\Cell under the function setValueExplicit inside the switch case added a new case like bellow
case DataType::TYPE_DATETIME:
$cValue=Date::PHPToExceldate(strtotime($pValue));
if (is_string($cValue) && !is_numeric($cValue)) {
throw new Exception('Invalid numeric value for datatype DateTime');
}
$this->value = 0 + $cValue;

break;

@ziming
Copy link

ziming commented Nov 24, 2021

fixed for me in the latest patch

oleibman pushed a commit to oleibman/PhpSpreadsheet that referenced this issue Jan 4, 2022
Fix PHPOffice#2373. Excel can handle DateTime/Date/Time as a string if the datatype of the cell is set to "d". The string is, apparently, supposed to follow the ISO8601 spec. Openpyxl can be configured to generate a file with such values, so I've added support and set up unit tests. Excel, naturally, converts such a string input into its numeric representation of the date/time stamp. So will PhpSpreadsheet, so a call to setValueExplicit specifying Date format will actually see the cell wind up with Numeric format - there is no way (and no reason) for the Date type to 'stick'.
oleibman added a commit that referenced this issue Jan 14, 2022
Fix #2373. Excel can handle DateTime/Date/Time as a string if the datatype of the cell is set to "d". The string is, apparently, supposed to follow the ISO8601 spec. Openpyxl can be configured to generate a file with such values, so I've added support and set up unit tests. Excel, naturally, converts such a string input into its numeric representation of the date/time stamp. So will PhpSpreadsheet, so a call to setValueExplicit specifying Date format will actually see the cell wind up with Numeric format - there is no way (and no reason) for the Date type to 'stick'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants