Jump to content

PHPExcel read TRUE or FALSE as text and not logical operator


vikaspa

Recommended Posts

Dear All
Using following code

We can read data properly
except when cell value stored is “TRUE” or “FALSE”
I get 1 and blank
I want TRUE or FALSE as text and not logical operator

How to read / get only values stored in cell

My code

include(‘PHPExcel-develop/Classes/PHPExcel/IOFactory.php’);

try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch(Exception $e) {
die(‘Error loading file "’.pathinfo($inputFileName,PATHINFO_BASENAME).’": '.$e->getMessage());
}

$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$arrayCount = count($allDataInSheet);

// the to get cell data
$excelsrno=trim($allDataInSheet[$i][“A”]);
$q= trim($allDataInSheet[$i][“B”]);
$a1= trim($allDataInSheet[$i][“C”]);

$a2= trim($allDataInSheet[$i]["D"] ); $a3= trim($allDataInSheet[$i]["E"] ); $a4= trim($allDataInSheet[$i]["F"] ); $a= preg_replace('/[^0-9]/', '', trim($allDataInSheet[$i]["G"])); $level=trim($allDataInSheet[$i]["H"]); $marks=trim($allDataInSheet[$i]["I"]);

Link to comment
Share on other sites

If the value in the cell is a logical true/false then there's no amount of PHP code you can write which will suddenly make it be text. But you can go into the sheet and mark that cell/column as text - that might work.

Of course, if the value is true/false and you want "true"/"false" then you could simply handle that. Perhaps with a ternary, like "$variable = $cell ? 'TRUE' : 'FALSE'".

Link to comment
Share on other sites

Dear All

I tacked this issue in following manner

when php read a cell that  stores "TRUE" or "FALSE"

suppose

php variable $a1 stores cell A:1<TRUE>

php variable $a2 stores cell A:2<FALSE>

in this case a1=1 when it gets ($a1 php value) value "TRUE"

and a2(cell A:2 value)  will have value NULL ($a2 php value)

-------------------------------------------------------

php variable $a2  stores cell A:1<TRUE>

php variable $a1 stores cell A:2<FALSE>

   if ( ($a2=='') or ($a2==' ') or ($a2=='')) // check for false and oter variable eis true
            {
                    $a2='FALSE';
                    $a1='TRUE';
            } 

php variable $a2 stores cell A:1<FALSE>

php variable $a2 stores cell A:2<TRUE>

in this case a2=1 when it gets value "TRUE"

and a2(cell A:2 value)  will have value NULL

-------------------------------------------------------

if ( ($a1=='') or ($a1==' ') or ($a1==''))  ) // check for false and other variable true
            {
                    $a1='FALSE';
                    $a2='TRUE';
            } 


        

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.