vikaspa Posted February 24, 2023 Share Posted February 24, 2023 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"]); Quote Link to comment https://forums.phpfreaks.com/topic/315944-phpexcel-read-true-or-false-as-text-and-not-logical-operator/ Share on other sites More sharing options...
requinix Posted February 24, 2023 Share Posted February 24, 2023 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'". Quote Link to comment https://forums.phpfreaks.com/topic/315944-phpexcel-read-true-or-false-as-text-and-not-logical-operator/#findComment-1605987 Share on other sites More sharing options...
vikaspa Posted February 25, 2023 Author Share Posted February 25, 2023 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/315944-phpexcel-read-true-or-false-as-text-and-not-logical-operator/#findComment-1606001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.