PHPExcel合并与拆分单元格


    
    
    
    
  1. $objPHPExcel;
  2. $filepath="c:\temp.xlsx";
  3. try {
  4. $objReader = PHPExcel_IOFactory::createReader('Excel2007');
  5. $objPHPExcel = $objReader->load($filepath);
  6. } catch (Exception $e) {
  7. die();
  8. }
  9. $column_index = "A";
  10. //清空要合并的首行单元格值,用于填充合并后的单元格值
  11. $objPHPExcel->getActiveSheet()->setCellValue($column_index.''.$beginRow,'');
  12. //合并单元格,值为''
  13. $objPHPExcel->getActiveSheet()->mergeCells($column_index.''.$beginRow.":".$column_index.''.$endRow);
  14. //拆分单元格,将清空合并前单元格的值并还原合并前单元格的样式
  15. $objPHPExcel->getActiveSheet()->unmergeCells($column_index.''.$beginRow.":".$column_index.''.$endRow);


参考:
Merge cells in PHPExcel
PHPExcel: How to Merge Cells


来自为知笔记(Wiz)


你可能感兴趣的:(PHPExcel合并与拆分单元格)