PHPExcel. How to check if current cell is merged w

2020-07-15 15:15发布

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?

标签: php phpexcel
1条回答
ゆ 、 Hurt°
2楼-- · 2020-07-15 15:45
$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.

查看更多
登录 后发表回答