Giter VIP home page Giter VIP logo

Comments (11)

adrilo avatar adrilo commented on May 13, 2024

@renciebautista, can you please give me more details on what the error is exactly? Are you writing a CSV or XLSX file?

from spout.

anmoroz avatar anmoroz commented on May 13, 2024

Hello.
I insert the following data:

I receive a file XLSX:

The format of the cell must be numeric, but it turns out a text.

from spout.

adrilo avatar adrilo commented on May 13, 2024

Tested and verified. If anyone wants to give a try fixing that one, please do so :) I'll be happy to help!

from spout.

adrilo avatar adrilo commented on May 13, 2024

@renciebautista, @anmoroz, can you please give me more info on how this is problematic for you?

By default, values are treated as numbers so "Standard" actually means "number" (int or float). Also, if you read the generated file, it will give you a float back, not a string.

from spout.

anmoroz avatar anmoroz commented on May 13, 2024

I need to add pivot table, which is located in a separate file. But pivot table is destroyed
For standard cell type, I can not use the formula without conversion.

I have studied the documentation of Microsoft - seem your code is correct. But the data in the cell is not a number.
I do not know what the problem.

from spout.

adrilo avatar adrilo commented on May 13, 2024

You should be able to use standard cells as numeric values without any conversion. This is what happens when you manually create an Excel spreadsheet and don't specify the cell format. You can also use pivot table without specifying the cell format.

I think that your problem is not linked to this. By the way, I'm not sure how you create you pivot table but this is not supported by Spout. Closing this issue as it's not a actual issue.

from spout.

jaspal747 avatar jaspal747 commented on May 13, 2024

Facing this same issue. Spout will prefix ' to the number in xlsx (when I open the file in LibreOffice, it shows this character. In excel, it adds the green flag to the top left corner of the cell. When we remove the ' and save the file, Excel correctly formats the cell as a number). Nothing related to pivoting. This is just a general issue.
Screenshot 2020-03-04 at 8 34 35 PM

from spout.

jaspal747 avatar jaspal747 commented on May 13, 2024

We found a solution for this. In the WriterEntityFactory.php, in the createRowFromArray() fn, we added a check for is_numeric and casted numbers to doubles.
So the updated function looks like this now:

public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null) {

    $cells = array_map(function ($cellValue) {
        /**
         * Cast the $cellValue to the correct type based on the value
         */
        if (is_numeric($cellValue)) {
              $cellValue = (double) $cellValue;
        }

        return new Cell($cellValue);
        
    }, $cellValues);

    return new Row($cells, $rowStyle);
}

from spout.

jaspal747 avatar jaspal747 commented on May 13, 2024

The deeper issue is here:

    public static function isNumeric($value)
    {
        $valueType = gettype($value);

        return ($valueType === 'integer' || $valueType === 'double');
    }

The CellTypeHelper strictly checks that numbers are only ints and doubles.
This should be updated to the simple:

    public static function isNumeric($value)
    {
        return is_numeric($value);
    }

from spout.

adrilo avatar adrilo commented on May 13, 2024

I think the initial code was what you proposed but it was changed to checking type directly. While using is_numeric works for your use case, it breaks other cases (I think some people expect "123" to not be numeric but a string.

from spout.

jaspal747 avatar jaspal747 commented on May 13, 2024

isNumeric() should mean is_numeric.. I don't see why outputting "123" (string) as 123 (number) in xslx would cause some people's excels to break.

from spout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.