0
Reply

How cIncrement PHPExcel column dynamically with dynamic name

Saafia NM

Saafia NM

Dec 28 2017 2:45 AM
242
Hi,
 
i am trying to loop columns in a row using another loop result. That is, i have to show date of Sundays/Mondays/Tuesdays... belongs to a month in dynamic columns of an Excel sheet using PHPExcel. My code is:
 
$lastColumn = $objSheet->getHighestColumn();
$lastColumn++;
for ($column = 'E'; $column != $lastColumn; $column++) {
$date_new='';
$str = $year.'-'.$month.'-';
for($i=1; $i<31; $i++)
{
$ddd = $str.$i;
$date = date('Y-m-D-d', $time = strtotime($ddd) );
if( strpos($date, $day) )
{
$date_new = date('d-m-Y', $time = strtotime($ddd) );
}
}
$objSheet->getCell($column.'3')->setValue($date_new);
}
 
I am getting the result as :
 
E F G H
25-12-2017 25-12-2017 25-12-2017 25-12-2017

I have to get like:
E F G H
04-12-2017 11-12-2017 18-12-2017 25-12-2017
 
Each loop individually giving the result. But nested loop is not working properly. What is the error in my code? Please help me to find out....