Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8547113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:11:47+00:00 2026-06-11T13:11:47+00:00

I have an array that can store numbers in such as 01, 01A, 01B,

  • 0

I have an array that can store numbers in such as 01, 01A, 01B, 02, 2, and When I get this value using PHPExcel, it’s being removed the ‘0’s in case of 01, 02, for example. To solve this problem, I tried to format the row where these values will be stored in excel and set it as text type, just like in the following code:

    $objPHPExcel->setActiveSheetIndexByName('BlocksList');
    $objPHPExcel->getActiveSheet()->fromArray($blockNames, null, 'A2');
    $latestBLColumn = $objPHPExcel->getActiveSheet()->getHighestDataColumn();
    $column = 'A';
    $row = 1;
    for ($column = 'A'; $column != $latestBLColumn; $column++) {
        $objPHPExcel->getActiveSheet()->getStyle($column.$row)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
    }
    $objPHPExcel->getActiveSheet()->fromArray($blockNames, null, 'A1');

So, by doing this, I get the array with numbers like 01, 01A, 02, 02B… and I store it in the Row A2. I get the highest Column to use this value in the condition For. In this condition, I set for the Row 1 in the range A until the highest column, to be formated as text.

My template is generated, and all the numbers are in text format, but the problem is that I think when I use the “fromArray()” method, it transforms the numbers of the array before I can get it right in excel.
Do you have any idea of how can I solve this problem??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:11:48+00:00Added an answer on June 11, 2026 at 1:11 pm

    Formatting using a number format affects the way a number is displayed, not the way it is stored.

    You’ll have to store the numbers explicitly as strings, so you can’t use fromArray().
    Use setCellValueExplicit() or setCellValueExplicitByColumnAndRow() instead, passing a $pDataType argument of PHPExcel_Cell_DataType::TYPE_STRING.

    EDIT

    Note that you can also set styles for a range of cells, so there’s no need to add the overhead of the for loop:

    $range = 'A'.$row.':'.$latestBLColumn.$row;
    $objPHPExcel->getActiveSheet()
        ->getStyle($range)
        ->getNumberFormat()
        ->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
    

    EDIT #2 Using a cell binder

    Create a customised cell value binder:

    class PHPExcel_Cell_MyValueBinder extends PHPExcel_Cell_DefaultValueBinder
        implements PHPExcel_Cell_IValueBinder 
    { 
        public function bindValue(PHPExcel_Cell $cell, $value = null) 
        { 
            // sanitize UTF-8 strings 
            if (is_string($value)) { 
                $value = PHPExcel_Shared_String::SanitizeUTF8($value); 
            } 
    
            // Implement your own override logic 
            if (is_string($value) && $value[0] == '0') { 
                $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING); 
                return true; 
            } 
    
            // Not bound yet? Use default value parent... 
            return parent::bindValue($cell, $value); 
        } 
    } 
    

    To avoid any problems with the autoloader, create this in the /Classes/PHPExcel/Cell directory. Otherwise, give the class your own non-PHPExcel name, and ensure that it’s loaded independently.

    Then, before using your fromArray() call, tell PHPExcel to use your value binder instead of the default binder:

    PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_MyValueBinder() );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that store data. If I subtract two arrays I get
Ok so lets say I have an array that can be 0 - X
I have a struct-array that contains details of different reports that can be run.
I have an array that contains @sign in the object. I can't access that
I have an array of pointers to a base class, so that I can
Does anyone know do there have any way that I can encrypt the array
Assume that we have multiple arrays of integers. You can consider each array as
I have an array that looks something like this: Array ( [0] => apple
I have an array that looks like this: [ Object actions: Array[2] comments: Object
I have a number that is get from a web page, such that $number=12-34-33-87-54-................

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.