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

Returning date on non date value #801

Open
AntonioCS opened this issue Mar 22, 2021 · 2 comments
Open

Returning date on non date value #801

AntonioCS opened this issue Mar 22, 2021 · 2 comments

Comments

@AntonioCS
Copy link

I have the following in an excel file:
image

In Libreoffice calc I can see the file is set as Number but when I read a row and use the toArray() method I am getting the following:

image

This is the code that is generating this:


        $reader = ReaderEntityFactory::createReaderFromFile($filePath);
        $reader->setShouldFormatDates(true);
        $reader->open($filePath);
        /** @var \Box\Spout\Reader\XLSX\Sheet $sheet */
        foreach ($reader->getSheetIterator() as $sheet) {
            /** @var \Box\Spout\Common\Entity\Row $row */
            foreach ($sheet->getRowIterator() as $row) {
                fputcsv($csvFileHandle, $row->toArray(), $delimiter, $enclosure, $escape_char);
            }

With this set: $reader->setShouldFormatDates(true);

I then get the following:

image

Is there an option somewhere to "dumb down" spout and have it just return everything as text, don't try to be smart and parse things just return text, that is all I need.

@adrilo
Copy link
Collaborator

adrilo commented Apr 13, 2021

Hi!

Unfortunately, such an option does not exist.

Regarding your issue, it looks like it's caused by this: https://github.com/box/spout/blob/master/src/Spout/Reader/XLSX/Manager/StyleManager.php#L297-L319

The pattern "#,##0 PCE" is considered as a date because of the presence of the "E" (which represents a date format). Although "PCE" should be preceded by a backslash to work properly, so I'm not sure how it actually works. If you have the possibility to upload a test file, that'd be helpful!

@lewa
Copy link

lewa commented Jan 16, 2022

Hi @adrilo, I encountered the same issue with the following custom format that also matches /(?<!\\)e/i pattern:

"EUR" #,##0.00

styles.xml:

<numFmt numFmtId="164" formatCode="&quot;EUR&quot;\ #,##0.00"/></numFmts>

Test file

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

3 participants