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

时间:2016-03-21 19:35:16

标签: php excel

嗨,大家好我想在这里做的是将两组两个单元合并在一起,但每当我运行这个时,我会得到一个致命错误,说明这个

  

致命错误:在第128行的/home3/hutch/public_html/MurphyNew/SendDocument.php中调用未定义的方法PHPExcel :: mergeCells()

任何人都知道这是为什么。这是我的代码:

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 个答案:

答案 0 :(得分:0)

修正了Mark Ba​​ker所说的问题,所以我的代码现在看起来像这样:

Pattern pattern = Pattern.compile("(\\S+)|(\\d+)|(\\s+)");
Matcher m = pattern.matcher(input);
if (m.find()) {
    if (m.group(1) != null) { // non-space

    }
    if (m.group(2) != null) { // digit

    }
    if (m.group(3) != null) { // space

    }
}