Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Support for DateTime when writing XLSX #662

Open
stof opened this issue Jun 27, 2019 · 11 comments
Open

Support for DateTime when writing XLSX #662

stof opened this issue Jun 27, 2019 · 11 comments

Comments

@stof
Copy link

stof commented Jun 27, 2019

The XLSX writer (and maybe also ODS, I haven't check) is missing support for date cells.

@mcorteel-harel
Copy link

There is an inconsistency in the code I think.
In Box\Spout\Writer\XLSX\Manager\WorksheetManager::getCellXml and Box\Spout\Writer\ODS\Manager\WorksheetManager::getCellXml, the case elseif ($cell->isDate()) is not implemented, though Box\Spout\Common\Entity\Cell supports it.
Also, when exporting to CSV, Cell::__toString() tries to cast a DateTime to a string, which is not possible and produces an exception.

@schrieveslaach
Copy link

#735 adds this to ODT.

@ChronicLogic
Copy link

PR #751 adds XLSX.

@adrilo
Copy link
Collaborator

adrilo commented May 14, 2021

There is an inconsistency in the code I think.
In Box\Spout\Writer\XLSX\Manager\WorksheetManager::getCellXml and Box\Spout\Writer\ODS\Manager\WorksheetManager::getCellXml, the case elseif ($cell->isDate()) is not implemented, though Box\Spout\Common\Entity\Cell supports it.
Also, when exporting to CSV, Cell::__toString() tries to cast a DateTime to a string, which is not possible and produces an exception.

This is true. Cell could support DateTime objects but full support is not ready, hence the error.

@mu1f407
Copy link

mu1f407 commented Jan 3, 2022

Hi, I recently faced this issue of missing support for dates for XLSX in my project. I saw that there were some PRs for this. I think the nicest one was #816. For me this solution is great and it's according to specification. The fact that some clients (Google Docs was mentioned) don't support it doesn't bother me. This shouln't be the reason for not merging this functionality. It works in Excel, is according to spec and it doesn't break anything.

@adrilo Would it be possible to reconsider merge of this PR? Thanks.

@Slamdunk
Copy link

Slamdunk commented Mar 3, 2022

Solved in openspout/openspout#13

@mcorteel-harel
Copy link

@Slamdunk Thanks! Any idea when this will be released?

@Slamdunk
Copy link

Slamdunk commented Mar 3, 2022

Released now in v3.6.0

Be aware that you need to specify the number format to have the output you need.

@mcorteel-harel
Copy link

mcorteel-harel commented Mar 3, 2022

@Slamdunk Could you give an example? Would that work (seems weird)?

$style = (new StyleBuilder())
    ->setFormat('0.000')
    ->build();
$cell = WriterEntityFactory::createCell(new \DateTime(), $style);

EDIT: Missing build() method

@Slamdunk
Copy link

Slamdunk commented Mar 3, 2022

$style = (new StyleBuilder())
    ->setFormat('yyyy-mm-dd');
$cell = WriterEntityFactory::createCell(new \DateTime(), $style);

@mcorteel-harel
Copy link

👍 Thanks a lot!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants