本文实例讲述了PHPExcel合并与拆分单元格的方法。分享给大家供大家参考,具体如下:$objPHP
本文实例讲述了PHPExcel合并与拆分单元格的方法。分享给大家供大家参考,具体如下:
$objPHPExcel;
$filepath="c:\temp.xlsx";
try {
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load($filepath);
} catch (Exception $e) {
die();
}
$column_index = "A";
//清空要合并的首行单元格值,用于填充合并后的单元格值
$objPHPExcel->getActiveSheet()->setCellValue($column_index.''.$beginRow,'');
//合并单元格,值为''
$objPHPExcel->getActiveSheet()->mergeCells($column_index.''.$beginRow.":".$column_index.''.$endRow);
//拆分单元格,将清空合并前单元格的值并还原合并前单元格的样式
$objPHPExcel->getActiveSheet()->unmergeCells($column_index.''.$beginRow.":".$column_index.''.$endRow);
参考:
Merge cells in PHPExcel PHPExcel: How to Merge Cells
PHPExcel 合并 拆分 单元格