Open stof opened 5 years ago
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.
PR #751 adds XLSX.
There is an inconsistency in the code I think. In
Box\Spout\Writer\XLSX\Manager\WorksheetManager::getCellXml
andBox\Spout\Writer\ODS\Manager\WorksheetManager::getCellXml
, the caseelseif ($cell->isDate())
is not implemented, thoughBox\Spout\Common\Entity\Cell
supports it. Also, when exporting to CSV,Cell::__toString()
tries to cast aDateTime
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.
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 Thanks! Any idea when this will be released?
Released now in v3.6.0
Be aware that you need to specify the number format to have the output you need.
@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
$style = (new StyleBuilder())
->setFormat('yyyy-mm-dd');
$cell = WriterEntityFactory::createCell(new \DateTime(), $style);
:+1: Thanks a lot!
The XLSX writer (and maybe also ODS, I haven't check) is missing support for date cells.