PHPExcel.如何检查当前单元格是否与另一个单元格合并?
问题描述:
我使用PHPExcel将Excel文件导入到我的网站.例如,有两个单元格A1和A2都合并了.有没有办法找出A1是否合并到另一个单元格(A2或其他)?
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?
答
$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;
}
}
由于phpexcel存储有关合并单元格信息的方式,我认为没有更好的解决方案.
I think there isn't better solution because of the way phpexcel stores information about merged cells.