I would like to fill in the empty spaces of a csv column and its in one column using phpexcel I have added a demo for your viewing: The flow check B2 is its not empty go the next B3 if B3 is empty take value from B2.
Here is demo:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="200" border="1">
  <tr>
    <td>Apple</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Banna</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>
<p>The final outcome</p>
<table width="200" border="1">
  <tr>
    <td>Apple</td>
  </tr>
  <tr>
    <td>Apple</td>
  </tr>
  <tr>
    <td>Apple</td>
  </tr>
  <tr>
    <td>Banna</td>
  </tr>
  <tr>
    <td>Banna</td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>

This is what i have come up with please help. its just one column i want to populate any empty fields

<?php
include'../Classes/PHPExcel.php';
include'../Classes/PHPExcel/IOFactory.php';
$objReader = new PHPExcel_Reader_CSV();
$objReader->setSheetIndex(0);
$objPHPExcel = $objReader->load('../Output/Basefile121101_2238.csv');
$highestRow = $objPHPExcel->getActiveSheet()->getHighestRow();
$COLB="";
$COLB3=$objPHPExcel->getActiveSheet()->getCell('B3')->getValue();
echo $COLB;



for ($i=2;$i<$highestRow;$i++){
if($COLB!=""){

$COLB=$objPHPExcel->getActiveSheet()->getCell('B'.$i)->getValue();
$valcol=$COLB;
$SETVAL=$objPHPExcel->getActiveSheet()->setCellValue('B'.$i, $valcol);
/*$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
$objWriter->save('../Output/Basefile121101_2238.csv');*/
echo $valcol=$COLB."<br>";
}
else{

$counter=0;
$counter++;
$results=$i-$counter;
$COLB=$objPHPExcel->getActiveSheet()->getCell('B'.$i)->getValue();
$valcol=$COLB;

  $SETVAL=$objPHPExcel->getActiveSheet()->setCellValue('B'.$results, $valcol);
 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
$objWriter->save('../Output/Basefile121101_2238.csv');
}
 }
?>
Member Avatar
LastMitch

@tapuwa2002

I would like to fill in the empty spaces of a csv column and its in one column using phpexcel I have added a demo for your viewing: The flow check B2 is its not empty go the next B3 if B3 is empty take value from B2.

You just want fill the column with data? Am I right?

Since B2 column has data once go to B3 column if it's empty then fill B3 column with data from B2 column? Is this right?

Instead of getValue(); used setValue();

setValue(); mean you target a column or row and transfer the data.

What you are saying is that I use set value through out. But now I want it to loop B3 gets filled. but what if B4 has already a value it must skip it but if B5 does it will take B4 value.

The answer was not correct regarding the question asked.

So what is the correct answer then? Do please share...