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

New Post: How to properly write values with leading zeroes with its unknown length

$
0
0
I'm working with values like:
0406440452
017649106486
040 28803190
I can't create mutual format for them...Seems like matching these values by separate regexes and applying specific format is only way to do it. What would you say?

P.S.: placing apostrophe is okay but I didn't figured the way how to do it without showing it in Excel...


UPDATE1

I've implemented possible solution:
  1. I divided my values on 2 types: only numbers and numbers with spaces. Made appropriate regexes for them.
  2. For only numbers I do:
                $valueLength = strlen($value);

                $numberFormat = '0';

                for($i = 1; $i <= $valueLength;$i++) {
                    $numberFormat = $numberFormat . '#';
                }

                $cell->getStyle()->getNumberFormat()->setFormatCode($numberFormat);
                $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_NUMERIC);
                $cell->getStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
As a result I recieve format like 0#########, depending from numbers amount
For values with spaces I can make similar logic as in 2(but add space in format).

What do you think about all of this, is it good idea at all?

Viewing all articles
Browse latest Browse all 2707


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