Export to GitHub

php-excel - issue #8

fix Number Stored as Text error


Posted on Oct 1, 2007 by Swift Camel

What steps will reproduce the problem? 1. add some rows that have numbers in them 2. download 3. Excel gives Number Stored as text error.

What is the expected output? What do you see instead? Excel gives Number Stored as text error.

What version of the product are you using? On what operating system? 1.0 on Mac OSX.

Please provide any additional information below. Here is my fix:

    foreach ($array as $k => $v):
        $ssType = "String";
        if(is_numeric($v)) {
            $ssType = "Number";
        }
        $cells .= "<Cell><Data ss:Type=\"".$ssType."\">" .

utf8_encode($v) . "</Data></Cell>\n";

    endforeach;

Comment #1

Posted on Jul 7, 2009 by Happy Hippo

If the above doesn't work try this

foreach($line_arr as $col) { $dtype = (is_numeric($col)) ? 'x:num':''; $line.="".$col.""; }

Comment #2

Posted on Sep 10, 2009 by Swift Horse

Thanks for your input. There is a new branch available:

http://code.google.com/p/php-excel/source/browse/#svn/branches/version02

This version addresses your issue. In Germany we have the problem that the automagic type identification may lead to the corruption of article numbers starting with a 0 (zero) or postcodes. This is why I set the types to String by default.

However, the new version will support the automatic identification of types, when you set a certain parameter in the constructor:

$xls = new Excel_XML('UTF-8', true);

Using 'true' will activate the automatic conversion, so that numeric strings get defined as Number in the XML.

Comment #3

Posted on Sep 10, 2009 by Swift Horse

I will address this issue with a new version and/or a patch for version 1.

Comment #4

Posted on Sep 10, 2009 by Swift Horse

Thanks again for posting your fix. I've addressed this issue in the new version 1.1, which is available in the [http://code.google.com/p/php-excel/downloads/list download section] of the project.

However, activating the auto-type identification remains optional since there are cases where you do not want the library to autoconvert values (for example: german postcodes starting with 0).

Comment #5

Posted on Nov 10, 2012 by Massive Camel

i had the same issue, just removing the white space(s) before or after the strings - Solved. :D

Status: Fixed

Labels:
Type-Defect Priority-Medium