PHPExcel. How to check if current cell is merged w

2020-07-15 15:32发布

问题:

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?

回答1:

$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.



标签: php phpexcel