Quantcast
Channel: PHPExcel Forum Rss Feed
Viewing all articles
Browse latest Browse all 2707

New Post: solution for numbers stored as text

$
0
0
harshshahi wrote:
I have included AdvancedValueBinder.php
PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() ); in my code and it is working fine for all :)
except number format like 23,222.

I have included below code in AdvancedValueBinder.php .But still it is showing error ico with salary.

// Style logic - Numbers
    if ($dataType === PHPExcel_Cell_DataType::TYPE_NUMERIC) {
        // Leading zeroes?
        if (preg_match('/^\d+,\d+$/', $value)) {
            // Convert value to string
            $cell->setValueExplicit( $value, PHPExcel_Cell_DataType::TYPE_STRING);

            // Set style
            $cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1 );

            return true;
        }
    } 
Please look into it
Thank you! I was running out of ideas, I have an array of usernames, many of which include a leading zero, and I could find no way to make it work, your tip of using setValueExplicit with the TYPE_STRING works!

This however does not, I think it is a bug, since the style is showing correctly in Excel (Text), but the leading zero is gone:
$objPHPExcel->setActiveSheetIndex(0)->getDefaultStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
$objPHPExcel->setActiveSheetIndex(0)->fromArray($Users);

I also tried using like: $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', '0123Hello'); in combination with the FORMAT_TEXT above - the 0 is gone...

Viewing all articles
Browse latest Browse all 2707

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>