1

enter image description here

This is my excel sheet from where m trying to get the L and M column but only the second value in my case the values are L6= 3.74 and M6= 457.27 This is my current code

$sheet = $objPHPExcel->getSheet();
$highestRow = $sheet->getHighestRow();
for ($row=5; $row <= $highestRow; $row++) 
{ 
    $rowData = $sheet->rangeToArray('B' . $row . ':'. 'B' . $row, NULL, TRUE, FALSE); 
    $rowDataA = $sheet->rangeToArray('L' . $row . ':'. 'M' . $row, NULL, TRUE, FALSE);
    print_r($rowDataA);
}

this is what print_r returns Array ( [0] => Array ( [0] => 23 3.74 [1] => 721 457.27 ) ) is there anyway i can get 3.74 and 457.27 only and not the first value

  • I too thought the same but those are stored in different cells and the one who has provided me the excel has mentioned that both represents different things.. and in our case we need the second value – Monika Nishad Sep 08 '20 at 11:08
  • Sorry, I deleted my comment so your reply doesn't make sense. I thought I hadn't read the question correctly, that you were trying to extract `.74` and `.27` until I read it again. – droopsnoot Sep 08 '20 at 11:09

1 Answers1

2
 $rowDataA = $sheet->rangeToArray('L' . $row . ':'. 'M' . $row, NULL, TRUE, FALSE);
 $value1 = explode(' ', $rowDataA[0][0]);
 echo $value1[1];

This is what can be done and alternatively if that somehow does not work replace space with something else and then use explode function and it will work.

$rowDataA[0][0] = preg_replace('/\s+/', ' ', $rowDataA[0][0]);