Reputation: 47
I have some data in array $header1
, $header2
and $data
. The case is to insert all these arrays to excel file where header is already ready, that is:
Another headers will be set after inserting of $header1
and $header2
.
Now the main issue is to insert $header1
array to merged column:
Or first insert data and then merge them:
From my side I have tried a lot of solutions , but nothing...
MY CODE :
$excel2->setActiveSheetIndex(4);
$row = 6;
$col = 2;
$col_letter = 'D';
foreach($header1 as $key=>$value) {
$excel2->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
$col=$col+2;
$merge = "'".$col_letter.$row.":".(++$col_letter).$row."'";
$excel2->getActiveSheet()->mergeCells($merge);
$col_letter++;
}
Take into account that $header1
array's data is unpredictable and the count of data can be over 50.
Any suggestion will be appreciated. Thanks.
Upvotes: 0
Views: 2639
Reputation: 47
It Seems I have solved issue myself referring to PHPExcel Column Loop
$row = 26;
$col = 2;
$j = 'C';
foreach($hesablar as $key=>$value) {
$excel2->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
$col=$col+2;
$i = $j++;
$excel2->getActiveSheet()->mergeCells($i.$row.':'.$j.$row);
echo $i.$row.':'.$j.$row.'<br />';
$j++;
}
Upvotes: 1