Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel. How to check if current cell is merged with another?

Tags:

php

phpexcel

I use PHPExcel to import Excel files to my site. For example, there is two cells, A1 and A2, both merged. Is there a way to to find out is A1 merged to another cell (A2 or other) or not?

like image 802
Taras Bulgakov Avatar asked Sep 04 '11 14:09

Taras Bulgakov


1 Answers

$workbook = new PHPExcel;
$sheet = $workbook->getActiveSheet();
$sheet->mergeCells('A1:E1');

$cell = $sheet->getCell('A1');

// Check if cell is merged
foreach ($sheet->getMergeCells() as $cells) {
    if ($cell->isInRange($cells)) {
        echo 'Cell is merged!'
        break;
    }
}

I think there isn't better solution because of the way phpexcel stores information about merged cells.

like image 72
Kamil Dziedzic Avatar answered Sep 23 '22 18:09

Kamil Dziedzic