dtrz99313
dtrz99313
2016-03-21 19:35
采纳率: 100%
浏览 86
已采纳

致命错误:PHPExcel在尝试合并单元格时?

Hi guys all i'm trying to do here is merge two sets of two cells together, however whenever I run this I get a fatal error that says this

Fatal error: Call to undefined method PHPExcel::mergeCells() in /home3/hutch/public_html/MurphyNew/SendDocument.php on line 128

Anyone know why this is. Here's my code:

Include_once 'PHP/PHPExcel.php';

    $sheet = new PHPExcel();
    $activeSheet = $sheet->getActiveSheet();
    $sheet->getActiveSheet()->setTitle('Senior Managers Site Tour');
    $sheet->getActiveSheet()->getColumnDimension('A')->setWidth(77);

    $styleArray = array(
    'borders' => array(
        'allborders' => array(
            'style' => PHPExcel_Style_Border::BORDER_THIN
            )
        )
    );

    $sheet->getActiveSheet()->getStyle('A5:D7')->applyFromArray($styleArray);
    unset($styleArray); 
    $sheet->mergeCells('C6:D6');
    $sheet->mergeCells('C7:D7');

    $activeSheet->setCellValue('C2','Senior Managers Site Tour');

    $activeSheet->setCellValue('B5','Site / Project / Object:');
    $activeSheet->setCellValue('C5',$spo);
    $activeSheet->setCellValue('D5','Contract Number:');
    $activeSheet->setCellValue('E5',$cont);
    $activeSheet->setCellValue('B6','Site Manager:');
    $activeSheet->setCellValue('C6',$site);
    $activeSheet->setCellValue('B7','Job / Task Description:');
    $activeSheet->setCellValue('C7',$job);

    $activeSheet->setCellValue('B9','OBSERVATION');
    $activeSheet->setCellValue('B10','Breif Description:');
    $activeSheet->setCellValue('B11',$des1);
    $activeSheet->setCellValue('C10','Agreed Action:');
    $activeSheet->setCellValue('C11',$act1);
    $activeSheet->setCellValue('D10','Close Date:');
    $activeSheet->setCellValue('D11',$date1);

    $activeSheet->setCellValue('B13','GOOD PRACTICE');
    $activeSheet->setCellValue('B14','Breif Description:');
    $activeSheet->setCellValue('B15',$des2);
    $activeSheet->setCellValue('C14','Agreed Action:');
    $activeSheet->setCellValue('C15',$act2);
    $activeSheet->setCellValue('D14','Close Date:');
    $activeSheet->setCellValue('D15',$date2);

    $activeSheet->setCellValue('B17','FEEDBACK GIVEN / RECEIVED');
    $activeSheet->setCellValue('B18','Breif Description:');
    $activeSheet->setCellValue('B19',$des3);
    $activeSheet->setCellValue('C18','Agreed Action:');
    $activeSheet->setCellValue('C19',$act3);
    $activeSheet->setCellValue('D18','Close Date:');
    $activeSheet->setCellValue('D19',$date3);

    $activeSheet->setCellValue('B20','GENERAL IMPRESSION');
    $activeSheet->setCellValue('B21','1 = No evidence / poor / no understanding');
    $activeSheet->setCellValue('C21','2 = Some evidence / understanding / not consistent');
    $activeSheet->setCellValue('B22','3 = Requirements in place / basic unerstanding');
    $activeSheet->setCellValue('C22','4 = Detailed understanding / more than minimum standards');

    $activeSheet->setCellValue('B24','CULTURE');
    $activeSheet->setCellValue('B25','Is the CDP obvious - You Said / We Did Boards; Feedback Stations; Posters?:');
    $activeSheet->setCellValue('C25',$P1Radio1);
    $activeSheet->setCellValue('B26','Are there any Speak Up Coaches on this site?');
    $activeSheet->setCellValue('C26',$P1Radio2);
    $activeSheet->setCellValue('B27','Are Focus Leader meetings happening?:');
    $activeSheet->setCellValue('C27',$P1Radio3);
    $activeSheet->setCellValue('B28','Mention the Mental Tools, do people understand them?:');
    $activeSheet->setCellValue('C28',$P1Radio4);
    $activeSheet->setCellValue('B29','Ask what "Never Harm" means to the teams:');
    $activeSheet->setCellValue('C29',$P1Radio5);

    $activeSheet->setCellValue('B31','GENERAL IMPRESSION (SYSTEM)');
    $activeSheet->setCellValue('B32','Are first impressions good, site signage, induction etc?:');
    $activeSheet->setCellValue('C32',$P2Radio1);
    $activeSheet->setCellValue('B33','Is the site tidy, well laid out etc?:');
    $activeSheet->setCellValue('C33',$P2Radio2);
    $activeSheet->setCellValue('B34','Are morning briefings / daily risk assessment carried out?:');
    $activeSheet->setCellValue('C34',$P2Radio3);
    $activeSheet->setCellValue('B35','Have all the team been briefed & signed onto the RAMS?:');
    $activeSheet->setCellValue('C35',$P2Radio4);
    $activeSheet->setCellValue('B36','Ask what they would do if there was a change in the work activity i.e. not in RAMS?:');
    $activeSheet->setCellValue('C36',$P2Radio5);

    $activeSheet->setCellValue('B38','GENERAL IMPRESSION (COMMENTS)');
    $activeSheet->setCellValue('B39','Additional Comments:');
    $activeSheet->setCellValue('C39',$add);

    $activeSheet->setCellValue('A41','COMPLETED BY');
    $activeSheet->setCellValue('A42','Name:');
    $activeSheet->setCellValue('B42',$name);
    $activeSheet->setCellValue('A43','Title:');
    $activeSheet->setCellValue('B43',$title);
    $activeSheet->setCellValue('A44','Date:');
    $activeSheet->setCellValue('B44',$date);

    $objWriter = PHPExcel_IOFactory::createWriter($sheet, 'Excel5');    
    $objWriter->save('Senior Managers Site Tour.xls');
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtnpf35197
    dtnpf35197 2016-03-21 20:52
    已采纳

    Fixed the issue here it was as Mark Baker said, so my code now looks like this:

    Include_once 'PHP/PHPExcel.php';
    
    
    $objPHPExcel = new PHPExcel();
    $activeSheet = $objPHPExcel->getActiveSheet();
    $objPHPExcel->getActiveSheet()->setTitle('Senior Managers Site Tour');
    $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(77);
    
    $styleArray = array(
        'borders' => array(
            'allborders' => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
                )
            )
        );
    
    $objPHPExcel->getActiveSheet()->getStyle('A5:D7')->applyFromArray($styleArray);
    unset($styleArray); 
    $objPHPExcel->getActiveSheet()->mergeCells('C6:D6');
    $objPHPExcel->getActiveSheet()->mergeCells('C7:D7');
    
    点赞 评论

相关推荐